#include <TFunction_Logbook.hxx>
#include <StdFail_NotDone.hxx>
-#include <utilities.h>
+#include <TopExp.hxx>
+#include <utilities.h>
//@@ include required header files here @@//
+enum
+{
+ SQUARE,
+ HEXAGON
+};
//=======================================================================
//function : GetID
//purpose :
TopoDS_Shape aShape;
// Getting data
- double R = aData.GetR();
- double Ratio = aData.GetRatio();
+ double R = aData.GetR();
+ double Ratio = aData.GetRatio();
+ int Pattern = aData.GetType();
// Build reference disk (in the global coordinate system)
- TopoDS_Shell S = MakeDisk( R, Ratio );
+ TopoDS_Shape aDisk;
- if (aType == DIVIDEDDISK_R_RATIO) {
+ if (Pattern == SQUARE)
+ aDisk = MakeDiskSquare( R, Ratio );
+ else if (Pattern == HEXAGON)
+ aDisk = MakeDiskHexagon( R, Ratio );
+
+ if (aType == DIVIDEDDISK_R_RATIO)
+ {
int theOrientation = aData.GetOrientation();
- aShape = TransformShape(S, theOrientation);
+ aShape = TransformShape(aDisk, theOrientation);
}
- else if (aType == DIVIDEDDISK_R_VECTOR_PNT){
- // other construction modes here
- gp_Pnt P = gp::Origin();
- gp_Dir V = gp::DZ();
- aShape = TransformShape(S, P, V);
+ else if (aType == DIVIDEDDISK_R_VECTOR_PNT)
+ {
+ Handle(GEOM_Function) aRefPoint = aData.GetCenter();
+ Handle(GEOM_Function) aRefVector = aData.GetVector();
+ TopoDS_Shape aShapePnt = aRefPoint->GetValue();
+ TopoDS_Shape aShapeVec = aRefVector->GetValue();
+
+ if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
+ aShapeVec.ShapeType() == TopAbs_EDGE)
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
+ TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(anE, V1, V2, Standard_True);
+ if (!V1.IsNull() && !V2.IsNull())
+ {
+ gp_Vec aVec (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
+ gp_Dir aDir(aVec);
+ aShape = TransformShape(aDisk, aPnt, aDir);
+ }
+ }
}
if (aShape.IsNull()) return 0;
//=======================================================================
-//function : MakeDisk
+//function : MakeDiskHexagon
//purpose :
//=======================================================================
-TopoDS_Shell GEOMImpl_DividedDiskDriver::MakeDisk(double R, double Ratio) const
+TopoDS_Shell GEOMImpl_DividedDiskDriver::MakeDiskHexagon(double R, double Ratio) const
{
// Geometry
gp_Dir ZDir(0,0,1);
gp_Circ aCircle(Ax, R);
// Points
- gp_Pnt P1(0.01*Ratio*R,0,0);
+// gp_Pnt P4(0.01*Ratio*R,0,0);
+// gp_Pnt P3(R,0,0);
+// gp_Pnt P2 = P3.Rotated(Ax1,-M_PI/6.0);
+// gp_Pnt P1(P4.X(),
+// P4.X()/sqrt(3.0),0);
+ gp_Pnt P1(0.01*Ratio*R*sqrt(3.0)/2,0,0);
gp_Pnt P2(R,0,0);
gp_Pnt P3 = P2.Rotated(Ax1,M_PI/6.0);
gp_Pnt P4(P1.X(),
P1.X()/sqrt(3.0),0);
+
//surfaces
gp_Ax2 anAx (gp::XOY());
for (int i=1;i<=6;i++)
{
// Edges
+
// for Face1
E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed()));
E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
// Wires
+
//Wire1
aBuilder.MakeWire(W1);
if (i==1)
return S;
}
+//=======================================================================
+//function : MakeDiskSquare
+//purpose :
+//=======================================================================
+TopoDS_Shape GEOMImpl_DividedDiskDriver::MakeDiskSquare(double R, double Ratio) const
+{
+ // Geometry
+ gp_Dir ZDir(0,0,1);
+ gp_Dir XDir(1,0,0);
+ gp_Pnt Orig(0,0,0);
+
+ // Circle
+ gp_Ax1 Ax1(Orig,ZDir);
+ gp_Ax2 Ax(Orig,ZDir,XDir);
+ gp_Circ aCircle(Ax, R);
+
+ // Points
+ gp_Pnt P1(0.01*Ratio*R,0,0);
+ gp_Pnt P2(R,0,0);
+
+ //surfaces
+ gp_Ax2 anAx (gp::XOY());
+ Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
+
+ // Topology
+
+ // Vertices
+ TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
+ TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
+
+ TopoDS_Vertex V1 = V1_init;
+ TopoDS_Vertex V2 = V2_init;
+
+ //Rotation
+ gp_Trsf myTrsf;
+ myTrsf.SetRotation(Ax1, M_PI/2);
+
+ BRepBuilderAPI_Transform xform(myTrsf);
+ xform.Perform(V1,Standard_True);
+ TopoDS_Vertex V1_rotated = TopoDS::Vertex(xform.Shape());
+ xform.Perform(V2,Standard_True);
+ TopoDS_Vertex V2_rotated = TopoDS::Vertex(xform.Shape());
+
+ // Declaration of shapes (used in the loop)
+ TopoDS_Edge E1, E2, E3, E4;
+ TopoDS_Wire W1, W2;
+ TopoDS_Face F1, F2;
+ TopoDS_Shell S;
+
+ BRep_Builder aBuilder;
+ aBuilder.MakeWire(W2); // Central Wire
+ aBuilder.MakeShell(S); // Shell
+
+ // Initialisation of edges
+ TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
+ E1 = E1_init;
+
+ for (int i=1;i<=4;i++)
+ {
+ // Edges
+ // for Face1
+
+ E3 = BRepBuilderAPI_MakeEdge(V2_rotated,TopoDS::Vertex(V1_rotated.Reversed()));
+ if (i == 4)
+ {
+ E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_init.Reversed()));
+ E4 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V1.Reversed()));
+ }
+ else
+ {
+ E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_rotated.Reversed()));
+ E4 = BRepBuilderAPI_MakeEdge(V1_rotated,TopoDS::Vertex(V1.Reversed()));
+ }
+
+ // Wires
+ //Wire1
+ aBuilder.MakeWire(W1);
+ if (i==1)
+ aBuilder.Add(W1,E1);
+ else
+ aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
+ aBuilder.Add(W1,E2);
+ if (i==4)
+ aBuilder.Add(W1,TopoDS::Edge(E1_init.Reversed()));
+ else
+ aBuilder.Add(W1,E3);
+ aBuilder.Add(W1,E4);
+
+ // Wire central
+ aBuilder.Add(W2,TopoDS::Edge(E4.Reversed()));
+
+ // Faces creation
+ F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
+
+ //Shell
+ aBuilder.Add(S, F1);
+
+ // rotation
+ V1=V1_rotated;
+ V2=V2_rotated;
+
+ xform.Perform(V1_rotated,Standard_True);
+ V1_rotated = TopoDS::Vertex(xform.Shape());
+ xform.Perform(V2_rotated,Standard_True);
+ V2_rotated = TopoDS::Vertex(xform.Shape());
+
+ // "Increment" of edges
+ E1=E3;
+ }
+ // Central square Face
+ F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
+ aBuilder.Add(S, F2);
+
+ return S;
+}
+
+
//=======================================================================
//function : TrasformShape(TopoDS_Shape aShape,int theOrientation)
//purpose : Perform shape transformation accordingly with specified