1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d;
21
22 import java.util.ArrayList;
23 import javax.vecmath.Point3d;
24 import javax.vecmath.Vector3d;
25 import javax.vecmath.Vector4d;
26 import java.awt.Dimension;
27 import camera3d.action.*;
28 import camera3d.gui.ViewportFrame;
29 import camera3d.gui.FrameSwitcherPane;
30 import camera3d.gui.ViewportWindowManager;
31 import camera3d.event.SelectionChangedEvent;
32
33 /***
34 * Object which receives requests from graphical components and generates actions
35 * for an ActionExecutor.
36 *
37 * @author Fábio Roberto de Miranda
38 * @version 1.0
39 */
40 public class GUIControl implements SelectionChangeListener {
41
42
43 public static boolean debugflag = false;
44 public static boolean viewportsInJInternalFrames = false;
45
46
47 private ActionQueue queue;
48 private ActionExecutor executor; // We need to know a reference to an actionExecutor so that
49 // we can wake it up if it is dead
50 private ViewportWindowManager viewportManager;
51 private J3DBase base;
52
53 /*** List of objects in the scene graph which are currently selected.*/
54 private ArrayList selectedObjects = new ArrayList();
55
56 // The existence of these attributes departs from the GUIControl concept.
57 // added solely to implement the "save environment functionality"
58 private FrameSwitcherPane selectionSwitcherPane;
59 private FrameSwitcherPane editionSwitcherPane;
60
61 /*** Object that generates a XML description from a list of VcObjects or vice-versa */
62 private XMLConverter converter = new XMLConverter();
63
64 /***
65 * Constructor that initializes the J3DBase and ActionQueue objects.
66 */
67 public GUIControl(J3DBase base, ActionQueue queue) {
68 this.base = base;
69 this.queue = queue;
70 }
71
72 /***
73 * Loads a file describing an environment configuration
74 * @param filename complete location of the file to be loaded
75 */
76 public void loadFile(String filename){
77 LoadXMLAction action = new LoadXMLAction(filename);
78 pushInQueue(action);
79 }
80
81 /***
82 * Loads a content file (currently, only VRML2.0 format is supported).
83 * @param filename complete location of the file to be loaded
84 */
85 public void importFile(String filename){
86 FileOpenAction action = new FileOpenAction(filename);
87 pushInQueue(action);
88 }
89
90 // added 27/06/2002 - Carlos
91 /***
92 * Saves a file describing an environment configuration.
93 * @param filename complete location of the file to be saved
94 */
95 public void saveFile(String filename){
96 SaveXMLAction action = new SaveXMLAction(filename);
97 pushInQueue(action);
98 }
99
100 /***
101 * Sets the viewport window manager to be used by VirtualCamera
102 * @param manager the window manager
103 */
104 public void setViewportManager(ViewportWindowManager manager){
105 this.viewportManager = manager;
106 }
107
108 /***
109 * Sets a viewport to show a given view
110 * @param viewportIndex index of viewport whose view will be changed
111 * @param view new VcView to be shown by the viewport
112 */
113 public void setViewInViewport(int viewportIndex, VcView view){
114 SetViewInViewportAction action = new SetViewInViewportAction(viewportIndex, view);
115 pushInQueue(action);
116 }
117
118 /***
119 * Sets the location in screen of a given viewport
120 * @param viewportIndex index of viewport whose location will be changed
121 * @param internal true if viewport should be shown internal to main window, false otherwise
122 * @param x X location of viewport in screen
123 * @param y Y location of viewport in screen
124 * @param width new width of viewport window
125 * @param height new height of viewport window
126 */
127 public void setViewportLocation(int viewportIndex, boolean internal, int x, int y, int width, int height){
128 SetViewportLocationAction action = new SetViewportLocationAction(viewportIndex, internal,x,y,width,height);
129 pushInQueue(action);
130 }
131
132 /***************************************************************************/
133 /***************************************************************************/
134 // WARNING: This section should not exist
135 /* The following methods deal with GUI issues directly; it would be good software
136 practice to isolate this kind of thing from GUIControl (despite its name).
137 However, putting these methods here was the best way we could find to implement
138 the saving/retrieving environment functionality. The ideal approach would be to
139 rethink the role of GUIControl, but we don't have time for that now.
140 Carlos 25/07/2002
141 */
142 public void setSelectionPane(FrameSwitcherPane selectionSwitcherPane){
143 this.selectionSwitcherPane = selectionSwitcherPane;
144 }
145
146 public void setEditionPane(FrameSwitcherPane editionSwitcherPane){
147 this.editionSwitcherPane = editionSwitcherPane;
148
149 }
150
151 FrameSwitcherPane getSelectionPane(){
152 return this.selectionSwitcherPane;
153 }
154
155 FrameSwitcherPane getEditionPane(){
156 return this.editionSwitcherPane;
157 }
158
159 // End of section
160 /***************************************************************************/
161 /***************************************************************************/
162
163
164 /***
165 * Sets the J3DBase for this object
166 * @param base the new J3DBase
167 */
168 /*
169 public void setJ3DBase(J3DBase base){
170 this.base = base;
171 }*/
172
173 /***
174 * Returns the J3DBase object used by this object.
175 */
176 public J3DBase getJ3DBase(){
177 /*
178 * ViewportInternalCombo uses this info to assemble Viewports that need
179 * scene graph information(which is inside J3DBase) to create objects used for picking.
180 */
181 return this.base;
182 }
183
184
185 public XMLConverter getXMLConverter(){
186 return this.converter;
187 }
188
189
190 /***
191 * Adds a viewport showing the default view
192 */
193 public void addViewport(){
194 // Adds a viewport with the default view
195 AddViewportAction action = new AddViewportAction();
196 pushInQueue(action);
197 }
198
199 /***
200 * Adds a view to the scene graph
201 * @param s name of the view to be added
202 */
203 public void addView(String s){
204 AddViewAction action = new AddViewAction(s);
205 pushInQueue(action);
206 }
207
208 /* returns ViewportWindowManager
209 method added to be used inside action that set up
210 the environment */
211 public ViewportWindowManager getViewportManager(){
212 return this.viewportManager;
213 }
214
215 /*
216 * GUIControl finds the objects that correspond to the given strings
217 * and finds references to them
218 */
219 public void changeViewInViewport(String viewportName, String viewName){
220 Viewport vp = viewportManager.getViewportByLabel(viewportName);
221 if (vp == null){
222 debugln("GUIControl: Could not find a Viewport with the specified name, aborting");
223 } else {
224 // Now we must try to get a reference to the right view
225 VcView view = (VcView)base.getByLabel(viewName);
226 if (view == null){
227 debugln("GUIControl: Could not find a view with the specified label in J3DBase, aborting");
228 return;
229 }
230 // If we arrive at this point, we must have both the Viewport (vp) and VcView (view) references
231 // so we can finally assemble the action
232 changeViewInViewport(vp, view);
233 }
234 }
235
236 public void changeViewInViewport(Viewport viewport, VcView view){
237 debugln("GUIControl: Change view in viewport called");
238 ViewChangeAction vchgAction = new ViewChangeAction(viewport, view);
239 pushInQueue(vchgAction);
240 }
241
242 /***
243 * Creates action to add a viewport window tothe application and pushes it into
244 * queue. The newly created viewport will show the view determined by the input
245 * VcView parameter. In case that parameter is null, the Viewport created will
246 * show the default view.
247 * @param v VcView that will be shown by the new viewport.
248 */
249 public void addViewport(VcView v){
250 AddViewportAction action;
251 if (v == null){
252 action = new AddViewportAction();
253 debugln("AddViewportAction assembled with null view");
254 } else {
255 action = new AddViewportAction(v);
256 }
257 pushInQueue(action);
258 }
259
260 public void addViewport(String viewName){
261 VcObject obj = base.getByLabel(viewName);
262 if (obj != null){
263 if (obj instanceof VcView){
264 VcView vcView = (VcView)obj;
265 addViewport(vcView);
266 }
267 }
268 }
269
270 /***
271 * Adds a viewport window that will show the view determined by the input VcView
272 * parameter. This method should not be called directly, but from an VcAction
273 * object.
274 * @param v VcView shown by new viewport window. Must be non null.
275 */
276 public void addViewportInGUI(VcView v){
277 if (v == null){
278 throw new NullPointerException("GUIControl: View used in viewport is null");
279 }
280 viewportManager.addViewport(v);
281 }
282
283 /***
284 * Used to print debug messages.
285 */
286 void debugln(String s){
287 if (GUIControl.debugflag){
288 System.out.println(s);
289 }
290 }
291
292 /***
293 * Sets the label of VcObject vcObj to a given String
294 */
295 public void renameVcObject(VcObject vcObj, String newName){
296 VcObjectRenameAction action = new VcObjectRenameAction(vcObj, newName);
297 pushInQueue(action);
298 }
299
300 /***
301 * Changes the label of the VcObject called oldName to newName.
302 */
303 public void renameVcObject(String oldName, String newName){
304 // Finds a reference to VcObject called oldName
305 VcObject vcObj = (VcObject)base.getByLabel(oldName);
306 // Them uses the function that is reference-based
307 renameVcObject(vcObj, newName);
308 }
309
310 /***
311 * Toggles presence of the helping grid in the virtual world.
312 */
313 public void toggleHelpingGrid(){
314 ToggleGridAction action = new ToggleGridAction();
315 pushInQueue(action);
316 }
317
318 public void translate(VcObject obj, TransformMode mode, Point3d destination){
319 TranslationAction action = new TranslationAction(obj, mode, destination);
320 pushInQueue(action);
321 }
322
323
324 public void translateX(String modeName, String objectName, double value){
325 VcObject obj = base.getByLabel(objectName);
326 TransformMode mode = TransformMode.modeForString(modeName);
327 if (obj != null){
328 translateX(mode, obj, value);
329 }
330 }
331
332 public void translateX(TransformMode mode, VcObject vcObj, double value){
333 TranslationAction action = new TranslationAction(vcObj, mode);
334 if (mode == TransformMode.ABSOLUTE){
335 action.setTranslationValues(value, vcObj.getYTranslation(), vcObj.getZTranslation());
336 } else if (mode == TransformMode.RELATIVE){
337 action.setTranslationValues(value, 0.0,0.0);
338 }
339 pushInQueue(action);
340 }
341
342 public void translateY(String modeName, String objectName, double value){
343 VcObject obj = base.getByLabel(objectName);
344 TransformMode mode = TransformMode.modeForString(modeName);
345 if (obj != null){
346 translateY(mode, obj, value);
347 }
348 }
349
350 public void translateY(TransformMode mode, VcObject vcObj, double value){
351 TranslationAction action = new TranslationAction(vcObj, mode);
352 if (mode == TransformMode.ABSOLUTE){
353 action.setTranslationValues(vcObj.getXTranslation(), value, vcObj.getZTranslation());
354 } else if (mode == TransformMode.RELATIVE){
355 action.setTranslationValues(0.0, value, 0.0);
356 }
357 pushInQueue(action);
358 }
359
360
361 public void translateZ(String modeName, String objectName, double value){
362 VcObject obj = base.getByLabel(objectName);
363 TransformMode mode = TransformMode.modeForString(modeName);
364 if (obj != null){
365 translateZ(mode, obj, value);
366 }
367 }
368
369 public void translateZ(TransformMode mode, VcObject vcObj, double value){
370 TranslationAction action = new TranslationAction(vcObj, mode);
371 if (mode == TransformMode.ABSOLUTE){
372 action.setTranslationValues(vcObj.getXTranslation(), vcObj.getYTranslation(), value);
373 } else if (mode == TransformMode.RELATIVE){
374 action.setTranslationValues(0.0, 0.0, value);
375 }
376 pushInQueue(action);
377 }
378
379 public void rotateX(String modeName, String objectName, double value){
380 VcObject obj = base.getByLabel(objectName);
381 TransformMode mode = TransformMode.modeForString(modeName);
382 if (obj != null){
383 rotateX(mode, obj, value);
384 }
385 }
386
387
388 public void rotateX(TransformMode mode, VcObject vcObj, double value){
389 RotationAction action = new RotationAction(vcObj, mode);
390 if (mode == TransformMode.ABSOLUTE){
391 action.setAngles(value, vcObj.getYAngleRad(),vcObj.getZAngleRad());
392 } else if (mode == TransformMode.RELATIVE){
393 action.setAngles(value,0.0, 0.0);
394 }
395 pushInQueue(action);
396 }
397
398 public void rotateY(String modeName, String objectName, double value){
399 VcObject obj = base.getByLabel(objectName);
400 TransformMode mode = TransformMode.modeForString(modeName);
401 if (obj != null){
402 rotateY(mode, obj, value);
403 }
404 }
405
406
407 public void rotateY(TransformMode mode, VcObject vcObj, double value){
408 RotationAction action = new RotationAction(vcObj, mode);
409 if (mode == TransformMode.ABSOLUTE){
410 action.setAngles(vcObj.getXAngleRad(), value, vcObj.getZAngleRad());
411 } else if (mode == TransformMode.RELATIVE){
412 action.setAngles(0.0, value, 0.0);
413 }
414 pushInQueue(action);
415 }
416
417
418 public void rotateZ(String modeName, String objectName, double value){
419 VcObject obj = base.getByLabel(objectName);
420 TransformMode mode = TransformMode.modeForString(modeName);
421 if (obj != null){
422 rotateZ(mode, obj, value);
423 }
424 }
425
426
427 public void rotateZ(TransformMode mode, VcObject vcObj, double value){
428 RotationAction action = new RotationAction(vcObj, mode);
429 if (mode == TransformMode.ABSOLUTE){
430 action.setAngles(vcObj.getXAngleRad(), vcObj.getYAngleRad(), value);
431 } else if (mode == TransformMode.RELATIVE){
432 action.setAngles(0.0, 0.0, value);
433 }
434 pushInQueue(action);
435 }
436
437 public void scaleX(String modeName, String objectName, double value){
438 VcObject obj = base.getByLabel(objectName);
439 TransformMode mode = TransformMode.modeForString(modeName);
440 if (obj != null){
441 scaleX(mode, obj, value);
442 }
443 }
444
445
446 public void scaleX(TransformMode mode, VcObject vcObj, double value){
447 ScalingAction action = new ScalingAction(vcObj, mode);
448 if(mode == TransformMode.ABSOLUTE){
449 action.setScalingValues(value, vcObj.getYScale(), vcObj.getZScale());
450 }
451 else if(mode == TransformMode.RELATIVE){
452 action.setScalingValues(value, 1, 1);
453 }
454 pushInQueue(action);
455 }
456
457
458 public void scaleY(String modeName, String objectName, double value){
459 VcObject obj = base.getByLabel(objectName);
460 TransformMode mode = TransformMode.modeForString(modeName);
461 if (obj != null){
462 scaleY(mode, obj, value);
463 }
464 }
465
466
467 public void scaleY(TransformMode mode, VcObject vcObj, double value){
468 ScalingAction action = new ScalingAction(vcObj, mode);
469 if(mode == TransformMode.ABSOLUTE){
470 action.setScalingValues(vcObj.getXScale(), value, vcObj.getZScale());
471 }
472 else if(mode == TransformMode.RELATIVE){
473 action.setScalingValues(1, value, 1);
474 }
475 pushInQueue(action);
476 }
477
478
479 public void scaleZ(String modeName, String objectName, double value){
480 VcObject obj = base.getByLabel(objectName);
481 TransformMode mode = TransformMode.modeForString(modeName);
482 if (obj != null){
483 scaleZ(mode, obj, value);
484 }
485 }
486
487
488 public void scaleZ(TransformMode mode, VcObject vcObj, double value){
489 ScalingAction action = new ScalingAction(vcObj, mode);
490 if(mode == TransformMode.ABSOLUTE){
491 action.setScalingValues(vcObj.getXScale(), vcObj.getYScale(), value);
492 }
493 else if(mode == TransformMode.RELATIVE){
494 action.setScalingValues(1, 1, value);
495 }
496 pushInQueue(action);
497 }
498
499 public void scale(String modeName, String objectName, double value){
500 VcObject obj = base.getByLabel(objectName);
501 TransformMode mode = TransformMode.modeForString(modeName);
502 if (obj != null){
503 scale(mode, obj, value);
504 }
505 }
506
507 public void scale(TransformMode mode, VcObject vcObj, double value){
508 ScalingAction action = new ScalingAction(vcObj, mode);
509 action.setScalingValues(value, value, value);
510 pushInQueue(action);
511 }
512
513 private void pushInQueue(VcAction action){
514 queue.push(action);
515 if (executor.isInterrupted()){
516 debugln("Command interpreting thread is interrupted");
517 }
518 if (!executor.isAlive()){
519 debugln("Command interpreting thread is dead");
520 }
521 }
522
523 public void changeProjectionPolicy(VcView vcView, int projectionPolicy){
524 ProjectionPolicyAction action = new ProjectionPolicyAction(vcView, projectionPolicy);
525 queue.push(action);
526 }
527
528 public void changeProjectionPolicy(String strView, String strPolicy){
529 int policy = VcView.PERSPECTIVE_PROJECTION;
530 VcView view = (VcView)base.getByLabel(strView);
531 if (view != null){
532 if (strPolicy=="PARALLEL"){
533 policy = VcView.PARALLEL_PROJECTION;
534 } else if (strPolicy == "PERSPECTIVE"){
535 policy = VcView.PERSPECTIVE_PROJECTION;
536 }
537 changeProjectionPolicy(view, policy);
538 } else {
539 debugln("Could not find a view with the name "+strView);
540 }
541 }
542
543 public void changeMovementPolicy(VcView vcView, int projectionPolicy){
544 MovementPolicyAction action = new MovementPolicyAction(vcView, projectionPolicy);
545 queue.push(action);
546 }
547
548 public void changeMovementPolicy(String strView, String strPolicy){
549 int policy = VcView.PHYSICAL_WORLD;
550 VcView view = (VcView)base.getByLabel(strView);
551 if (view != null){
552 if (strPolicy=="VIRTUAL"){
553 policy = VcView.VIRTUAL_WORLD;
554 } else if (strPolicy == "PHYSICAL"){
555 policy = VcView.PHYSICAL_WORLD;
556 }
557 changeMovementPolicy(view, policy);
558 } else {
559 debugln("Could not find a view with the name "+strView);
560 }
561 }
562
563 public void changeResizePolicy(VcView vcView, int projectionPolicy){
564 ResizePolicyAction action = new ResizePolicyAction(vcView, projectionPolicy);
565 queue.push(action);
566 }
567
568 public void changeResizePolicy(String strView, String strPolicy){
569 int policy = VcView.PHYSICAL_WORLD;
570 VcView view = (VcView)base.getByLabel(strView);
571 if (view != null){
572 if (strPolicy=="VIRTUAL"){
573 policy = VcView.VIRTUAL_WORLD;
574 } else if (strPolicy == "PHYSICAL"){
575 policy = VcView.PHYSICAL_WORLD;
576 }
577 changeResizePolicy(view, policy);
578 } else {
579 debugln("Could not find a view with the name "+strView);
580 }
581 }
582
583 public void setFieldOfView(String strView, double d){
584 VcView view = (VcView)base.getByLabel(strView);
585 setFieldOfView(view, d);
586 }
587
588
589 public void setFieldOfView(VcView view, double d){
590 FieldOfViewAction action = new FieldOfViewAction(view, d);
591 queue.push(action);
592 }
593
594
595 public void setActionExecutor(ActionExecutor executor){
596 this.executor = executor;
597 }
598
599 public void setLaserArrayGrid(VcLaserArray array, int nx, int ny, double dx, double dy){
600 debugln("__changing grid");
601 SetLaserArrayGridAction action = new SetLaserArrayGridAction(array, nx, ny, dx, dy);
602 queue.push(action);
603 }
604
605 public void changeLaserArrayColor(VcLaserArray array, double red, double green, double blue){
606 debugln("__changing color");
607 ChangeLaserArrayColorAction action = new ChangeLaserArrayColorAction(array, red,green, blue);
608 queue.push(action);
609 }
610
611 public void changeLaserSpotSize(VcLaserArray array, double size){
612 debugln("__changing size");
613 ChangeLaserSpotSizeAction action = new ChangeLaserSpotSizeAction(array, size);
614 queue.push(action);
615 }
616
617
618 public void addLight(int type, String name){
619 AddLightAction action = new AddLightAction(type, name);
620 queue.push(action);
621 }
622
623 public void addLight(String type, String name){
624 AddLightAction action = new AddLightAction(type, name);
625 queue.push(action);
626 }
627
628 public void changeLightColor(VcLight light, int red, int green, int blue){
629 LightColorChangeAction action = new LightColorChangeAction(light, red, green, blue);
630 queue.push(action);
631 }
632
633 public void changeLightColor(String light, int red, int green, int blue){
634 VcObject obj = base.getByLabel(light);
635 if (obj instanceof VcLight){
636 VcLight vcLight = (VcLight)obj;
637 this.changeLightColor(vcLight, red, green, blue);
638 }
639 }
640
641 public void changeLightState(VcLight light, boolean b){
642 LightStateAction action = new LightStateAction(light, b);
643 queue.push(action);
644 }
645
646 public void changeLightState(String lightName, int onOff){
647 boolean b = false;
648 switch (onOff){
649 case 0:
650 b = false;
651 break;
652 case 1:
653 b = true;
654 break;
655 }
656 VcLight light = (VcLight)base.getByLabel(lightName);
657 changeLightState(light, b);
658 }
659
660 public void changePointLightAttenuation(VcPointLight point, double constant, double linear, double quadratic){
661 PointLightAttenuationAction action = new PointLightAttenuationAction(point, constant, linear, quadratic);
662 queue.push(action);
663 }
664
665
666
667 public void changeSpotSpreadAngle(VcSpotLight spot, double angle){
668 SpotSpreadAction action = new SpotSpreadAction(spot, angle);
669 queue.push(action);
670 }
671
672 public void changeSpotSpreadAngle(String spotName, double angle){
673 VcObject obj = base.getByLabel(spotName);
674 if (obj instanceof VcSpotLight){
675 VcSpotLight spotLight = (VcSpotLight) obj;
676 changeSpotSpreadAngle(spotLight, angle);
677 }
678
679 }
680
681 public void changeSpotConcentration(VcSpotLight spot, double concentration){
682 SpotConcentrationAction action = new SpotConcentrationAction(spot, concentration);
683 queue.push(action);
684 }
685
686 public void changeSpotConcentration(String spotLightName, double concentration){
687 VcObject obj = base.getByLabel(spotLightName);
688 if (obj instanceof VcSpotLight){
689 VcSpotLight spotLight = (VcSpotLight)obj;
690 changeSpotConcentration(spotLight, concentration);
691 }
692 }
693
694 public void removeFromScene(String objectName){
695 VcObject obj = base.getByLabel(objectName);
696 if (obj != null){
697 removeFromScene(obj);
698 }
699 }
700
701 public void removeFromScene(VcObject vcObject){
702 DeleteAction action = new DeleteAction(vcObject);
703 queue.push(action);
704 }
705
706 public void saveJPGFile(Viewport viewport, String filename){
707 JPGSaveAction saveAction = new JPGSaveAction(viewport, filename);
708 queue.push(saveAction);
709 }
710
711
712 /***
713 * Saves a snapshot from a given viewport in a JPEG file
714 * This method enforces synchronous execution, i.e. the method will not return
715 * untill the action is completed
716 * @param viewport viewport from which generate the snapshot
717 * @param filename Name of the output file
718 */
719 public void saveJPGFileSync(Viewport viewport, String filename){
720 if (viewport==null){
721 System.out.println("saveJPGFileSync: viewport is null");
722 return;
723 }
724 Dimension d = viewport.getSize();
725 // blocks the action queue so no more actions are received
726 queue.setBlocked(true);
727 // wait till all actions already in queue are completed
728 while(!queue.isEmpty()){
729 try{
730 wait(100);
731 }catch(InterruptedException ie){
732 ie.printStackTrace();
733 System.out.println("Interrupted Exception while waiting for completion of tasks on queue");
734 }
735 }
736 // saves snapshot directly in viewport, avoiding queue
737 viewportManager.moveViewportToFront(viewport);
738 viewport.getCanvas3D().requestFocus();
739 // using the on-screen snapshot as the offscreen one
740 // made textures disappear in the resulting image
741 viewport.saveJPGFile(filename);
742 //viewport.saveJPGFile(filename,d.width,d.height);
743 // unblocks queue
744 queue.setBlocked(false);
745 }
746
747
748
749
750 public void saveJPGFile(Viewport viewport, String filename, int w, int h){
751 JPGSaveAction saveAction = new JPGSaveAction(viewport, filename, w, h);
752 queue.push(saveAction);
753 }
754
755 /*
756 public void saveJPGFileSync(Viewport viewport, String filename, int w, int h){
757 // blocks the action queue so no more actions are received
758 queue.setBlocked(true);
759 // wait till all actions already in queue are completed
760 while(!queue.isEmpty()) ;
761 // saves snapshot directly in viewport, avoiding queue
762 viewport.saveJPGFile(filename,w,h);
763 // unblocks queue
764 queue.setBlocked(false);
765 }
766 */
767 public void saveTXTFile(String filename){
768 TXTSaveAction saveAction = new TXTSaveAction(filename);
769 queue.push(saveAction);
770 }
771
772 public void saveJPGFile(String viewportName, String filename){
773 Viewport viewport = viewportManager.getViewportByLabel(viewportName);
774 // Put some warning to the user in case the requested viewport does not exists
775 if (viewport!=null){
776 saveJPGFile(viewport, filename);
777 }
778 }
779
780
781 /***
782 * Saves a snapshot from a given view in a JPEG file
783 * This method enforces synchronous execution, i.e. the method will not return
784 * untill the action is completed
785 * @param viewportName Name of the view from which generate the snapshot
786 * @param filename Name of the output file
787 */
788 public void saveJPGFileSync(String viewportName, String filename){
789 if(viewportManager==null){
790 System.out.println("saveJPGFileSync: viewportManager==null");
791 return;
792 }
793 Viewport viewport = viewportManager.getViewportByLabel(viewportName);
794 // Put some warning to the user in case the requested viewport does not exists
795 if (viewport!=null){
796 saveJPGFileSync(viewport, filename);
797 } else System.out.println("saveJPGFile: Viewport "+ viewportName +" not found");
798 }
799
800 public void saveJPGFile(String filename){
801 Viewport viewport = viewportManager.getViewportByLabel("Default View");
802 // Put some warning to the user in case the requested viewport does not exists
803 if (viewport!=null){
804 saveJPGFile(viewport, filename);
805 } else System.out.println("saveJPGFile: Viewport Default View not found");
806 }
807
808 /***
809 * Saves a snapshot from Default View in a JPEG file
810 * This method enforces synchronous execution, i.e. the method will not return
811 * untill the action is completed
812 * @param filename Name of the output file
813 */
814 public void saveJPGFileSync(String filename){
815 if(viewportManager==null){
816 System.out.println("saveJPGFileSync: viewportManager==null");
817 return;
818 }
819 Viewport viewport = viewportManager.getViewportByLabel("Default View");
820 // Put some warning to the user in case the requested viewport does not exists
821 if (viewport!=null){
822 saveJPGFileSync(viewport, filename);
823 } else System.out.println("saveJPGFile: Viewport Default View not found");
824 }
825
826 public void enableMessageInViewports(String s){
827 viewportManager.enableMessageInAllViewports(s);
828 }
829
830 public void disableMessageInViewports(){
831 viewportManager.disableMessageInAllViewports();
832 }
833
834 public boolean getDebugFlag(){
835 return this.debugflag;
836 }
837
838 public void setDebugFlag(boolean b){
839 this.debugflag = b;
840 }
841
842 public void frameObjectInView(VcView v, VcObject obj){
843 FrameObjectAction action = new FrameObjectAction(v, obj);
844 pushInQueue(action);
845 }
846
847 /*
848 * Frames all objects in view v
849 */
850 public void frameObjectsInView(VcView v){
851 FrameObjectAction action = new FrameObjectAction(v);
852 pushInQueue(action);
853 }
854
855 /*
856 * Frames all objects in view named label
857 */
858 public void frameObjectsInView(String label){
859 VcView v = (VcView)base.getByLabel(label);
860 if (v!=null){
861 frameObjectsInView(v);
862 }
863 }
864
865 /*
866 * Creates an action of LookAt type
867 */
868 public void lookAt(VcView view, VcObject vcObj){
869 if (view != null){
870 if (vcObj != null){
871 LookAtAction action = new LookAtAction(view, vcObj);
872 queue.push(action);
873 }
874 }
875 }
876
877 public void lookAt(String view, String vcObject){
878 VcView v = (VcView)base.getByLabel(view);
879 VcObject vcO = (VcObject)base.getByLabel(vcObject);
880 if (v != null){
881 if (vcO != null){
882 lookAt(v, vcO);
883 }
884 }
885 }
886
887
888 public void addDistanceMeasurer(){
889 AddDistanceMeasurerAction action = new AddDistanceMeasurerAction();
890 queue.push(action);
891 }
892
893 public void setMeasurerDirection(String measurerName, int direction, String axisName){
894 TransformScope scope = TransformScope.scopeForString(axisName);
895 setMeasurerDirection(measurerName,direction,scope);
896 }
897
898 public void setMeasurerDirection(String measurerName, int direction, TransformScope axis){
899 DistanceMeasurer measurer = (DistanceMeasurer)base.getByLabel(measurerName);
900 if (measurer!=null){
901 SetDistanceMeasurerDirectionAction action = new SetDistanceMeasurerDirectionAction(measurer, direction, axis);
902 queue.push(action);
903 } else {
904 debugln("Requested measurer was null.");
905 }
906 }
907
908 public double getMeasuredDistance(String measurerName){
909 // Cuidado: Pode ser que isto rode antes de alguma ação que está na fila e que mexa
910 // com a distância
911
912 DistanceMeasurer measurer = (DistanceMeasurer)base.getByLabel(measurerName);
913 if (measurer!=null){
914 return measurer.getDistance();
915 } else {
916 debugln("Requested measurer was null.");
917 return -1.0;
918 }
919 }
920
921 public void measureDistance(DistanceMeasurer measurer){
922 MeasureDistanceAction action = new MeasureDistanceAction(measurer);
923 queue.push(action);
924 }
925
926 /*
927 * Methods created for the debugging of the translationManipulator, but kept
928 * for subsequent use
929 */
930 public void addLine(Point3d p1, Point3d p2){
931 AddLineGizmoAction action = new AddLineGizmoAction(p1, p2);
932 queue.push(action);
933 }
934
935 public void setGizmoColor(byte r, byte g, byte b){
936 GizmoColorAction action = new GizmoColorAction();
937 action.setColor(r, g, b);
938 queue.push(action);
939 }
940
941 public void setColorAlternation(boolean b){
942 GizmoColorAction action = new GizmoColorAction();
943 action.setColorAlternation(b);
944 queue.push(action);
945 }
946
947 public void addLine(Point3d origin, Vector3d direction){
948 AddLineGizmoAction action = new AddLineGizmoAction(origin, direction);
949 queue.push(action);
950 }
951
952 public void startLineArray(){
953 StartLineArrayAction action = new StartLineArrayAction();
954 queue.push(action);
955 }
956
957 public void addLineSegment(Point3d p1, Point3d p2){
958 AddSegmentToLineArrayAction action = new AddSegmentToLineArrayAction(p1, p2);
959 queue.push(action);
960 }
961
962 public void finishLineArray(){
963 FinishLineArrayAction action = new FinishLineArrayAction();
964 queue.push(action);
965 }
966
967 public void setLineLength(double length){
968 System.out.println("guiControl.setLineLength: Yet to be implemented");
969 }
970
971 public void setPointWidth(double length){
972 System.out.println("guiControl.setPointWidth: Yet to be implemented");
973 }
974
975 public void setPlaneWidth(double length){
976 System.out.println("guiControl.setPlaneWidth: Yet to be implemented");
977 }
978
979
980 public void addPlane(Point3d p1, Point3d p2, Point3d p3){
981 AddPlaneGizmoAction action = new AddPlaneGizmoAction(p1, p2, p3);
982 queue.push(action);
983 }
984
985 public void addPlane(Vector4d plane){
986 AddPlaneGizmoAction action = new AddPlaneGizmoAction(plane);
987 queue.push(action);
988 }
989
990 public void addPlane(Point3d point, Vector3d normal){
991 AddPlaneGizmoAction action = new AddPlaneGizmoAction(point, normal);
992 queue.push(action);
993 }
994
995 public void addPoint(Point3d point){
996 AddPointGizmoAction action = new AddPointGizmoAction(point);
997 queue.push(action);
998 }
999
1000 public void clearBagGizmos(int clearRange){
1001 ClearGizmosAction action = new ClearGizmosAction(clearRange);
1002 queue.push(action);
1003 }
1004
1005 /***
1006 * Implements SelectionChangeListener. This way a GUIControl can always know of Selections
1007 * at a particular SelectionList
1008 */
1009 public void selectionChanged(SelectionChangedEvent event){
1010 debugln("GUIControl: notified of selection Changes");
1011 if(event.getAddedObjects().size()>0)
1012 selectedObjects.addAll(event.getAddedObjects());
1013 if(event.getRemovedObjects().size()>0)
1014 selectedObjects.removeAll(event.getRemovedObjects());
1015 }
1016
1017 public void dumpContentEdgesToFile(){
1018 /* this method is the only reason why GUIControl should be made
1019 a SelectionChangeListener, as it demands knowledge of objects
1020 currently selected. */
1021 debugln("GUIControl: dump...");
1022 if (selectedObjects.size() > 0){
1023 debugln("selectedObjects.size(): "+selectedObjects.size());
1024 Object obj = selectedObjects.get(0);
1025 if (obj instanceof VcContent){
1026 debugln("__found VcContent");
1027 DumpEdgesAction action = new DumpEdgesAction((VcContent)obj);
1028 queue.push(action);
1029 }
1030 }else System.out.println("GUIControl: No objects selected");
1031
1032 }
1033
1034 /***
1035 * TODO: Insert methods that allow insertion of Lines, Points and Planes
1036 * in a specific GeometryBag
1037 */
1038 }
This page was automatically generated by Maven