source: git/Singular/LIB/surfex/LampAdminUpdater.java @ 7661e1

fieker-DuValspielwiese
Last change on this file since 7661e1 was 3de2ca, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: surfex_0_90_00 git-svn-id: file:///usr/local/Singular/svn/trunk@11070 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.3 KB
Line 
1////////////////////////////////////////////////////////////////////////
2//
3// This file LampAdminUpdater.java is part of SURFEX.
4//
5////////////////////////////////////////////////////////////////////////
6
7////////////////////////////////////////////////////////////////////////
8//
9// SURFEX version 0.90.00
10// =================
11//
12// Saarland University at Saarbruecken, Germany
13// Department of Mathematics and Computer Science
14//
15// SURFEX on the web: www.surfex.AlgebraicSurface.net
16//
17// Authors: Oliver Labs (2001-2008), Stephan Holzer (2004-2005)
18//
19// Copyright (C) 2001-2008
20//
21//
22// *NOTICE*
23// ========
24// 
25// This program is free software; you can redistribute it and/or modify it
26// under the terms of the GNU General Public License as published by the
27// Free Software Foundation ( version 3 or later of the License ).
28//
29// See LICENCE.TXT for details.
30//
31/////////////////////////////////////////////////////////////////////////
32
33import javax.swing.*;
34import java.awt.*;
35
36public class LampAdminUpdater extends Thread {
37   
38    double lastjv4sxScale = 0;
39   
40    double[] lastCamPos={0.0,0.0,0.0};
41    double[] lastCamRot={0.0,0.0,0.0};
42   
43    double eps=0.0001;
44   
45    int zoomFac=1;
46   
47    String lastx = "0";
48    String lasty = "0";
49    String lastz = "0";
50    String lastx2 = "0";
51    String lasty2 = "0";
52    String lastz2 = "0";
53   
54    double lastzoom = 0;
55   
56    double factor;
57    double scaleMin;
58    double scaleMax;
59   
60    jv4surfex jv4sx;
61   
62    JTextField x=new JTextField("0");
63    JTextField y=new JTextField("0");
64    JTextField z=new JTextField("0");
65    JTextField x2=new JTextField("0");
66    JTextField y2=new JTextField("0");
67    JTextField z2=new JTextField("0");
68   
69    JSlider zoom;
70   
71    int genauigkeit=8;
72   
73    int timedist = 5; //50ms distanz zwischen updates
74   
75    LampAdminUpdater() {
76       
77    }
78   
79/*      public double[] getScaleForSurf(){
80//      return 1.0 / jv4sx.disp.getCamera().getScale()*surffactor;
81}
82*/
83    LampAdminUpdater(double factor, double smin, double smax) {
84//          System.out.println("factor:"+factor);
85//          this.factor=4/factor/1000;
86        scaleMin = smin;
87        scaleMax = smax;
88        this.factor=1/factor*(scaleMax-scaleMin)/1000;
89    }
90   
91    public void setScaleMinMax(double smin, double smax) {
92        scaleMin = smin;
93        scaleMax = smax;
94        this.factor=1/1.0*(smax-smin)/1000;
95    }
96   
97    public synchronized void setSlider(JSlider s) {
98        zoom = s;
99    }
100   
101    public synchronized void setPosTextFields(JTextField x, JTextField y, JTextField z) {
102        this.x = x;
103        this.y = y;
104        this.z = z;
105        //this.x2.setText(x.getText());
106       
107        //this.y2.setText(y.getText());
108       
109        //this.z2.setText(z.getText());
110    }
111   
112    public synchronized void setPosTextFields2(JTextField x, JTextField y, JTextField z) {
113       
114        //      System.out.println(0+" "+jv4sx.getCamPos()[2]);
115       
116       
117        this.x2 = x;
118        this.y2 = y;
119        this.z2 = z;
120       
121        //      System.out.println(0+".5 "+jv4sx.getCamPos()[2]);
122        //System.out.println(1+" "+x2.getText());
123        //this.x.setText(x.getText());
124       
125        //this.y.setText(y.getText());
126       
127        //this.z.setText(z.getText());
128        //updateLast();
129    }
130   
131    public synchronized void setJv4sx(jv4surfex j) {
132        jv4sx = j;
133    }
134   
135    public void run() {
136        while (true) {
137            try {
138                sleep(timedist);
139            } catch (Exception e) {
140               
141            }
142            // testen ob der Scale geaendert wurde
143            // in jv4sx:
144            /*  if (jv4sx.disp.getCamera().getScale() != lastjv4sxScale) {
145                update();
146                ///     System.out.println("1");
147               
148                } else {*/
149            //77                if (check(jv4sx.getCameraRotationYXZ(),lastCamRot)) {
150            //  update();
151            //  System.out.println(jv4sx.getCameraRotationYXZ()[0]+" "+lastCamRot[0]);
152            //  System.out.println("2");
153            //  } else {
154            if (check(jv4sx.getCamPos(), lastCamPos)) {
155                update();
156                //              System.out.println(":3");
157            } else {
158                // im Zoom-slider
159                if (zoom.getValue() != lastzoom) {
160                    updateZoom();
161                    //          System.out.println(":4");
162                } else {
163                    if (x.getText().compareTo(lastx) != 0
164                        || y.getText().compareTo(lasty) != 0
165                        || z.getText().compareTo(lastz) != 0) {
166                        updatePos();
167                        //              System.out.println(":5");
168                    }else{
169                        if (x2.getText().compareTo(lastx2) != 0
170                            || y2.getText().compareTo(lasty2) != 0
171                            || z2.getText().compareTo(lastz2) != 0) {
172                            updatePos2();
173                            //          System.out.println(":6");
174                        }
175                    }
176                }
177                //}
178                //}
179               
180            }
181           
182        }
183    }
184   
185    public synchronized boolean check(double[] a,double[] b){
186        for(int i=0;i<a.length;i++){
187           
188            if(a[i]-b[i]>eps){
189//                              System.out.println("............"+(a[i]-b[i]));
190               
191                return true;
192            }
193        }
194        return false;
195    }
196   
197    public synchronized void update() {
198        double[] pos=jv4sx.getCamPos();
199        if(pos[0]<lastCamPos[0]*100){
200            x.setText(getString((pos[0]+"")));
201            y.setText(getString((pos[1]+"")));
202            z.setText(getString((pos[2]+"")));
203            x2.setText(getString((pos[0]+"")));
204            y2.setText(getString((pos[1]+"")));
205            z2.setText(getString((pos[2]+"")));
206           
207//              System.out.println("factor:"+factor);
208//          zoom.setValue((int)(jv4sx.getScale()*zoomFac/factor));
209            zoom.setValue((int)((jv4sx.getScale()-scaleMin)/(scaleMax-scaleMin)*1000+0.5));
210           
211            //  System.out.println(2+" "+x2.getText());
212            updateLast();
213        }else{
214            updateZoom();
215        }
216    }
217   
218    /*public void setCamPos(double x,double y,double z){
219      updateLast();
220      }*/
221    public synchronized void updateZoom() {
222//      jv4sx.setScale((double)zoom.getValue()/zoomFac*factor);
223        jv4sx.setScale((scaleMin+(zoom.getValue())/1000.0*(scaleMax-scaleMin)));
224        double[] pos=jv4sx.getCamPos();
225        x.setText(getString((pos[0]+"")));
226        y.setText(getString((pos[1]+"")));
227        z.setText(getString((pos[2]+"")));
228        x2.setText(getString((pos[0]+"")));
229        y2.setText(getString((pos[1]+"")));
230        z2.setText(getString((pos[2]+"")));
231       
232        jv4sx.updateDisp();
233        updateLast();
234       
235       
236        //System.out.println(3+" "+x2.getText());
237    }
238    public synchronized void updatePos() {
239        jv4sx.setCamPos2(Double.valueOf(x.getText()+"0").doubleValue(),Double.valueOf(y.getText()+"0").doubleValue(),Double.valueOf(z.getText()+"0").doubleValue());
240//      zoom.setValue((int)(jv4sx.getScale()*zoomFac/factor));
241        zoom.setValue((int)((jv4sx.getScale()-scaleMin)/(scaleMax-scaleMin)*1000+0.5));
242        x2.setText(getString(x.getText()));
243        y2.setText(getString(y.getText()));
244        z2.setText(getString(z.getText()));
245       
246        jv4sx.updateDisp();
247       
248        updateLast();
249       
250        //System.out.println(4+" "+x2.getText());
251    }
252   
253    public synchronized void updatePos2() {
254        jv4sx.setCamPos2(Double.valueOf(x2.getText()+"0").doubleValue(),Double.valueOf(y2.getText()+"0").doubleValue(),Double.valueOf(z2.getText()+"0").doubleValue());
255//      zoom.setValue((int)(jv4sx.getScale()*zoomFac/factor));
256        zoom.setValue((int)((jv4sx.getScale()-scaleMin)/(scaleMax-scaleMin)*1000+0.5)); x.setText(getString(x2.getText()));
257        y.setText(getString(y2.getText()));
258        z.setText(getString(z2.getText()));
259       
260        jv4sx.updateDisp();
261       
262        updateLast();
263       
264        //System.out.println(5+".......... "+x2.getText());
265    }
266   
267    public synchronized void updateLast(){
268        lastjv4sxScale = jv4sx.getScale();
269       
270        lastCamPos=jv4sx.getCamPos();
271        lastCamRot=jv4sx.getCameraRotationYXZ();
272       
273        lastx = x.getText();
274       
275        lasty = y.getText();
276       
277        lastz = z.getText();
278        lastx2 = x2.getText();
279       
280        lasty2 = y2.getText();
281       
282        lastz2 = z2.getText();
283       
284        lastzoom = zoom.getValue();
285    }
286   
287   
288    public synchronized String getString(String s){
289        return (s+"          ").substring(0,8).replaceAll(" ","");
290    }
291}
Note: See TracBrowser for help on using the repository browser.