Adjusting testing cases for current state of OCCT
[occt.git] / samples / java / java / CASCADEView3d.java
1
2 //Title:        OpenCASCADE Samples
3 //Version:      
4 //Copyright:    Copyright (c) 1999
5 //Author:       User Interface group
6 //Company:      Matra Datavision
7 //Description:  
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import jcas.*;
13 import CASCADESamplesJni.*;
14 import util.*;
15
16 public class CASCADEView3d extends ViewCanvas
17 {
18   private V3d_Viewer myViewer = null;
19   private V3d_View myView = null;
20
21   private double currScale = 1.0;
22   private boolean degenerated = true;
23
24 //=======================================================================//
25 //                             Constructor                               //
26 //=======================================================================//
27   public CASCADEView3d(V3d_Viewer viewer)
28   {
29     myViewer = viewer;
30     myView = myViewer.CreateView();
31   }
32
33 //=======================================================================//
34 // Redefined operations
35 //=======================================================================//
36   /** Sets a handle of native window to CASCADE view */
37 //   public void setWindow3d(V3d_View view, int hiwin, int lowin)
38 //   {
39 //   }
40
41 //=======================================================================//
42 //   public void SetWindow()
43 //   {
44 //     int windowHandle = getWinData();
45 //     short hi, lo;
46 //     lo = (short) windowHandle;
47 //     hi = (short) (windowHandle >> 16);
48 //     setWindow3d(myView, hi, lo);
49 //   }
50
51 //=======================================================================//
52   public void FitAll()
53   {
54     if (myView != null)
55     {
56       myView.FitAll(0.01, true);
57       myView.ZFitAll(0.0);
58     }
59   }
60
61 //=======================================================================//
62   public void WindowFit(Rectangle rect)
63   {
64     if (myView != null)
65       myView.WindowFit(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
66   }
67
68 //=======================================================================//
69   public void Zoom(int x0, int y0, int x, int y)
70   {
71     if (myView != null)
72       myView.Zoom(x0, y0, x, y);
73   }
74
75 //=======================================================================//
76   public void ActivateGlobalPanning()
77   {
78     super.ActivateGlobalPanning();
79     if (myView != null)
80     {
81       currScale = myView.Scale();
82       myView.FitAll(0.01, false);
83     }
84   }
85
86 //=======================================================================//
87   public void Pan(int dx, int dy)
88   {
89     if (myView != null)
90       myView.Pan(dx, dy, 1.0);
91   }
92
93 //=======================================================================//
94   public void SetCenter(int x, int y)
95   {
96     if (myView != null)
97       myView.Place(x, y, currScale);
98   }
99
100 //=======================================================================//
101   public void StartRotation(int x0, int y0)
102   {
103     if (myView != null)
104     {
105       degenerated = myView.DegenerateModeIsOn();
106       myView.SetDegenerateModeOn();
107       myView.StartRotation(x0, y0, 0.0);
108     }
109   }
110
111 //=======================================================================//
112   public void Rotate(int x, int y)
113   {
114     if (myView != null)
115       myView.Rotation(x, y);
116   }
117
118 //=======================================================================//
119   public void EndRotation()
120   {
121     if (myView != null)
122       if (!degenerated)
123         myView.SetDegenerateModeOff();
124   }
125
126 //=======================================================================//
127   public void SetProjection(String type)
128   {
129     if (myView != null)
130     {
131       if (type.equals("Axo"))
132         myView.SetProj(V3d_TypeOfOrientation.V3d_XposYnegZpos);
133       else if (type.equals("Front"))
134         myView.SetProj(V3d_TypeOfOrientation.V3d_Yneg);
135       else if (type.equals("Top"))
136         myView.SetProj(V3d_TypeOfOrientation.V3d_Zpos);
137       else if (type.equals("Left"))
138         myView.SetProj(V3d_TypeOfOrientation.V3d_Xneg);
139       else if (type.equals("Back"))
140         myView.SetProj(V3d_TypeOfOrientation.V3d_Ypos);
141       else if (type.equals("Right"))
142         myView.SetProj(V3d_TypeOfOrientation.V3d_Xpos);
143       else if (type.equals("Bottom"))
144         myView.SetProj(V3d_TypeOfOrientation.V3d_Zneg);
145     }
146   }
147
148 //=======================================================================//
149   public void SetDegenerateMode(boolean isOn)
150   {
151     if (myView != null)
152     {
153       if (isOn)
154         myView.SetDegenerateModeOn();
155       else
156         myView.SetDegenerateModeOff();
157     }
158   }
159
160 //=======================================================================//
161   public void ResetView()
162   {
163     if (myView != null)
164       myView.Reset();
165   }
166
167 //=======================================================================//
168   public Color GetBackgroundColor()
169   {
170     if (myView != null)
171     {
172       Standard_Real aRed = new Standard_Real();
173       Standard_Real aGreen = new Standard_Real();
174       Standard_Real aBlue = new Standard_Real();
175
176       myView.BackgroundColor(Quantity_TypeOfColor.Quantity_TOC_RGB, aRed, aGreen, aBlue);
177
178       int red = (int) (aRed.GetValue()*255);
179       int green = (int) (aGreen.GetValue()*255);
180       int blue = (int) (aBlue.GetValue()*255);
181
182       return new Color(red, green, blue);
183     }
184     else
185       return super.GetBackgroundColor();
186   }
187
188 //=======================================================================//
189   public void SetBackgroundColor(Color color)
190   {
191     if (myView != null)
192     {
193       myView.SetBackgroundColor(Quantity_TypeOfColor.Quantity_TOC_RGB,
194                                 color.getRed()/255., color.getGreen()/255.,
195                                 color.getBlue()/255.);
196       myView.Update();
197     }
198   }
199
200 //=======================================================================//
201
202   public native void paint (Graphics g);
203 // commented
204 //   public void paint(Graphics g)
205 //   {
206 //     if (myView != null)
207 //     {
208 //       if (needResize)
209 //       {
210 //         myView.MustBeResized();
211 //         needResize = false;
212 //       }
213 //       myView.Redraw();
214 //     }
215 //     super.paint(g);
216 //   }
217
218 //=======================================================================//
219   public V3d_View getView()
220   {
221     return myView;
222   }
223 }