Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / java / src / SampleAISBasicPackage / SampleAISBasicPackage.cxx
1 #include <SampleAISBasicPackage.hxx>
2 #include <TCollection_AsciiString.hxx>
3 #include <AIS_InteractiveContext.hxx>
4 #include <AIS_Shape.hxx>
5 #include <AIS_Trihedron.hxx>
6 #include <AIS_Circle.hxx>
7 #include <AIS_Line.hxx>
8 #include <User_Cylinder.hxx>
9 #include <Geom_Line.hxx>
10 #include <Geom_Axis2Placement.hxx>
11 #include <GC_MakeCircle.hxx>
12 #include <gp_Pnt.hxx>
13 #include <gp_Lin.hxx>
14 #include <gp_Dir.hxx>
15 #include <BRepPrimAPI_MakeSphere.hxx>
16
17 #include <V3d_Viewer.hxx>
18 #include <V3d_View.hxx>
19
20 #ifdef WNT
21 #include <WNT_Window.hxx>
22 #include <Graphic3d_WNTGraphicDevice.hxx>
23 #else
24 #include <Xw_Window.hxx>
25 #include <Graphic3d_GraphicDevice.hxx>
26 #endif
27
28
29
30
31 //===============================================================
32 // Function name: CreateViewer
33 //===============================================================
34  Handle(V3d_Viewer) SampleAISBasicPackage::CreateViewer (const Standard_ExtString aName) 
35 {
36 #ifdef WNT
37 static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
38     
39   if (defaultDevice.IsNull()) 
40     defaultDevice = new Graphic3d_WNTGraphicDevice();
41   return new V3d_Viewer(defaultDevice, aName);
42 #else
43 static Handle(Graphic3d_GraphicDevice) defaultDevice;
44     
45   if (defaultDevice.IsNull())
46     defaultDevice = new Graphic3d_GraphicDevice("");
47   return new V3d_Viewer(defaultDevice, aName);
48 #endif //WNT
49 }
50
51 //===============================================================
52 // Function name: SetWindow
53 //===============================================================
54 void SampleAISBasicPackage::SetWindow (const Handle(V3d_View)& aView,
55                                        const Standard_Integer hiwin,
56                                        const Standard_Integer lowin)
57 {
58 #ifdef WNT
59   Handle(Graphic3d_WNTGraphicDevice) d = 
60     Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
61   Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
62 #else
63   Handle(Graphic3d_GraphicDevice) d = 
64     Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
65   Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
66 #endif
67   aView->SetWindow(w);
68 }
69
70
71
72  void SampleAISBasicPackage::DisplayTrihedron(const Handle(AIS_InteractiveContext)& aContext) 
73 {
74   Handle(AIS_Trihedron) aTrihedron;
75   Handle(Geom_Axis2Placement) anAxis=new Geom_Axis2Placement(gp::XOY());
76   aTrihedron=new AIS_Trihedron(anAxis);
77   aContext->Display(aTrihedron);
78 }
79
80  void SampleAISBasicPackage::DisplayCircle(const Handle(AIS_InteractiveContext)& aContext,
81                                            TCollection_AsciiString& Message) 
82 {
83   GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
84   Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
85   aContext->Display(anAISCirc);
86
87   Message = "\
88                 \n\
89 GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n\
90 Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n\
91 myAISContext->Display(anAISCirc); \n\
92                 \n";
93 }
94
95  void SampleAISBasicPackage::DisplayLine(const Handle(AIS_InteractiveContext)& aContext,
96                                          TCollection_AsciiString& Message) 
97 {
98   gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.));
99   Handle(Geom_Line) aLine = new Geom_Line(L);
100   Handle(AIS_Line) anAISLine = new AIS_Line(aLine);
101   aContext->Display(anAISLine); 
102
103   Message = "\
104                 \n\
105 gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n\
106 Handle(Geom_Line) aLine = new Geom_Line(L); \n\
107 Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n\
108 myAISContext->Display(anAISLine); \n\
109                 \n";
110 }
111
112  void SampleAISBasicPackage::DisplaySphere(const Handle(AIS_InteractiveContext)& aContext,
113                                            TCollection_AsciiString& Message) 
114 {
115   BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
116   Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
117   aContext->SetColor(anAISShape,Quantity_NOC_AZURE); 
118   aContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC);    
119   aContext->SetDisplayMode(anAISShape,1);
120   aContext->Display(anAISShape);        
121
122   Message = "\
123                 \n\
124 BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.); \n\
125 Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape()); \n\
126 myAISContext->SetColor(anAISShape,Quantity_NOC_AZURE); \n\
127 myAISContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC); \n\
128 myAISContext->SetDisplayMode(anAISShape,1); \n\
129 myAISContext->Display(anAISShape); \n\
130                 \n";
131 }
132
133  void SampleAISBasicPackage::DisplayCylinder(const Handle(AIS_InteractiveContext)& aContext,
134                                              TCollection_AsciiString& Message) 
135 {
136   Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.);
137   aContext->SetDisplayMode(aCyl,1);
138   aContext->Display(aCyl);      
139
140   Message = "\
141                 \n\
142 Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.); \n\
143 myAISContext->SetDisplayMode(aCyl,1); \n\
144 myAISContext->Display(aCyl); \n\
145  \n\
146 NOTE: a User_Cylinder is an object defined by the user. \n\
147 The User_Cylinder class inherits the AIS_InteractiveObject \n\
148 CASCADE class, its usage is the same as an AIS_InteractiveObject. \n\
149                 \n";
150 }
151