2 //Title: OpenCASCADE Samples
4 //Copyright: Copyright (c) 1999
5 //Author: User Interface group
6 //Company: Matra Datavision
10 import java.awt.event.*;
13 import CASCADESamplesJni.*;
16 public class CASCADEView3d extends ViewCanvas
18 private V3d_Viewer myViewer = null;
19 private V3d_View myView = null;
21 private double currScale = 1.0;
22 private boolean degenerated = true;
24 //=======================================================================//
26 //=======================================================================//
27 public CASCADEView3d(V3d_Viewer viewer)
30 myView = myViewer.CreateView();
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)
41 //=======================================================================//
42 // public void SetWindow()
44 // int windowHandle = getWinData();
46 // lo = (short) windowHandle;
47 // hi = (short) (windowHandle >> 16);
48 // setWindow3d(myView, hi, lo);
51 //=======================================================================//
56 myView.FitAll(0.01, true);
61 //=======================================================================//
62 public void WindowFit(Rectangle rect)
65 myView.WindowFit(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
68 //=======================================================================//
69 public void Zoom(int x0, int y0, int x, int y)
72 myView.Zoom(x0, y0, x, y);
75 //=======================================================================//
76 public void ActivateGlobalPanning()
78 super.ActivateGlobalPanning();
81 currScale = myView.Scale();
82 myView.FitAll(0.01, false);
86 //=======================================================================//
87 public void Pan(int dx, int dy)
90 myView.Pan(dx, dy, 1.0);
93 //=======================================================================//
94 public void SetCenter(int x, int y)
97 myView.Place(x, y, currScale);
100 //=======================================================================//
101 public void StartRotation(int x0, int y0)
105 degenerated = myView.DegenerateModeIsOn();
106 myView.SetDegenerateModeOn();
107 myView.StartRotation(x0, y0, 0.0);
111 //=======================================================================//
112 public void Rotate(int x, int y)
115 myView.Rotation(x, y);
118 //=======================================================================//
119 public void EndRotation()
123 myView.SetDegenerateModeOff();
126 //=======================================================================//
127 public void SetProjection(String type)
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);
148 //=======================================================================//
149 public void SetDegenerateMode(boolean isOn)
154 myView.SetDegenerateModeOn();
156 myView.SetDegenerateModeOff();
160 //=======================================================================//
161 public void ResetView()
167 //=======================================================================//
168 public Color GetBackgroundColor()
172 Standard_Real aRed = new Standard_Real();
173 Standard_Real aGreen = new Standard_Real();
174 Standard_Real aBlue = new Standard_Real();
176 myView.BackgroundColor(Quantity_TypeOfColor.Quantity_TOC_RGB, aRed, aGreen, aBlue);
178 int red = (int) (aRed.GetValue()*255);
179 int green = (int) (aGreen.GetValue()*255);
180 int blue = (int) (aBlue.GetValue()*255);
182 return new Color(red, green, blue);
185 return super.GetBackgroundColor();
188 //=======================================================================//
189 public void SetBackgroundColor(Color color)
193 myView.SetBackgroundColor(Quantity_TypeOfColor.Quantity_TOC_RGB,
194 color.getRed()/255., color.getGreen()/255.,
195 color.getBlue()/255.);
200 //=======================================================================//
202 public native void paint (Graphics g);
204 // public void paint(Graphics g)
206 // if (myView != null)
210 // myView.MustBeResized();
211 // needResize = false;
218 //=======================================================================//
219 public V3d_View getView()