0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / QAQuickPen / QAQuickPen.cxx
CommitLineData
7fd59977 1// File: QAQuickPen.cxx
2// Created: Thu Oct 24 18:03:14 2002
3// Author: Michael KUZMITCHEV
4// <mkv@russox>
5
6
7#include <QAQuickPen.ixx>
8
9#include <Draw_Interpretor.hxx>
10#include <DBRep.hxx>
11#include <DrawTrSurf.hxx>
12#include <AIS_InteractiveContext.hxx>
13#include <ViewerTest.hxx>
14#include <AIS_Shape.hxx>
15#include <TopoDS_Shape.hxx>
16
17#include <gp_Pnt.hxx>
18#include <gp_Ax2.hxx>
19#include <gp.hxx>
20#include <gp_Ax1.hxx>
21#include <gce_MakeCirc.hxx>
22#include <gp_Circ.hxx>
23#include <GC_MakeArcOfCircle.hxx>
24#include <BRepBuilderAPI_MakeEdge.hxx>
25#include <TopoDS_Edge.hxx>
26#include <BRepBuilderAPI_MakeWire.hxx>
27#include <TopoDS_Wire.hxx>
28#include <Geom_TrimmedCurve.hxx>
29#include <BRepOffsetAPI_ThruSections.hxx>
30//=======================================================================
31// OCC895
32//=======================================================================
33static Standard_Integer OCC895 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
34{
35 if (argc < 2 || argc > 5)
36 {
37 di << "Usage : " << argv[0] << " result [angle [reverse [order]]]" << "\n";
38 return 1;
39 }
40
41 const Standard_Real rad = 1.0;
42 const Standard_Real angle = (argc > 2)? atof(argv[2]) : 0.0;
43 const Standard_Integer reverse = (argc > 3)? atoi(argv[3]) : 0;
44 const Standard_Integer order = (argc > 4)? atoi(argv[4]) : 0;
45
46 // Make a wire from the first arc for ThruSections.
47 //
48 // This arc is rotated 5 degrees about the Z axis.
49 // I don't know why, but if we don't rotate it,
50 // the final shell is not twisted.
51 gp_Pnt center1(0,10,0);
52 gp_Ax2 axis1 = reverse?
53 gp_Ax2(center1, gp::DY(), gp::DZ()) : gp_Ax2(center1, -gp::DY(), gp::DX());
54 if (Abs(angle) > gp::Resolution())
c6541a0c 55 axis1.Rotate(gp_Ax1(center1, gp::DZ()), angle*M_PI/180.0);
7fd59977 56
57 gce_MakeCirc makeCirc1(axis1, rad);
58 if(!makeCirc1.IsDone()) return 1;
59 gp_Circ circ1 = makeCirc1.Value();
c6541a0c 60 GC_MakeArcOfCircle makeArc1(circ1, 0, M_PI/2, Standard_True);
7fd59977 61 if(!makeArc1.IsDone()) return 1;
62 Handle_Geom_TrimmedCurve arc1 = makeArc1.Value();
63
64 // Create wire 1
65 BRepBuilderAPI_MakeEdge makeEdge1(arc1, arc1->StartPoint(), arc1->EndPoint());
66 if(!makeEdge1.IsDone()) return 1;
67 TopoDS_Edge edge1 = makeEdge1.Edge();
68 BRepBuilderAPI_MakeWire makeWire1;
69 makeWire1.Add(edge1);
70 if(!makeWire1.IsDone()) return 1;
71 TopoDS_Wire wire1 = makeWire1.Wire();
72
73 // Make a wire from the second arc for ThruSections.
74 gp_Pnt center2(10,0,0);
75 gp_Ax2 axis2(center2, -gp::DX(), gp::DZ());
76
77 gce_MakeCirc makeCirc2(axis2, rad);
78 if(!makeCirc2.IsDone()) return 1;
79 gp_Circ circ2 = makeCirc2.Value();
c6541a0c 80 GC_MakeArcOfCircle makeArc2(circ2, 0, M_PI/2, Standard_True);
7fd59977 81 if(!makeArc2.IsDone()) return 1;
82 Handle_Geom_TrimmedCurve arc2 = makeArc2.Value();
83
84 // Create wire 2
85 BRepBuilderAPI_MakeEdge makeEdge2(arc2, arc2->StartPoint(), arc2->EndPoint());
86 if(!makeEdge2.IsDone()) return 1;
87 TopoDS_Edge edge2 = makeEdge2.Edge();
88 BRepBuilderAPI_MakeWire makeWire2;
89 makeWire2.Add(edge2);
90 if(!makeWire2.IsDone()) return 1;
91 TopoDS_Wire wire2 = makeWire2.Wire();
92
93 BRepOffsetAPI_ThruSections thruSect(Standard_False,Standard_True);
94 if (order)
95 {
96 thruSect.AddWire(wire1);
97 thruSect.AddWire(wire2);
98 }
99 else
100 {
101 thruSect.AddWire(wire2);
102 thruSect.AddWire(wire1);
103 }
104 thruSect.Build();
105 if(!thruSect.IsDone()) return 1;
106 TopoDS_Shape myShape = thruSect.Shape();
107
108 DBRep::Set(argv[1],myShape);
109
110 return 0;
111}
112
113void QAQuickPen::Commands(Draw_Interpretor& theCommands) {
114 char *group = "QAQuickPen";
115
116 theCommands.Add ("OCC895", "OCC895 result [angle [reverse [order]]]", __FILE__, OCC895, group);
117
118 return;
119}