xref: /petsc/src/sys/classes/draw/interface/dmouse.c (revision a6404fbfb1cfbf30d2bac9856cef3bf7411483d5)
1 
2 /*
3        Provides the calling sequences for all the basic PetscDraw routines.
4 */
5 #include <petsc/private/drawimpl.h>  /*I "petscdraw.h" I*/
6 
7 #undef __FUNCT__
8 #define __FUNCT__ "PetscDrawGetMouseButton"
9 /*@
10     PetscDrawGetMouseButton - Returns location of mouse and which button was
11     pressed. Waits for button to be pressed.
12 
13     Not collective (Use PetscDrawSynchronizedGetMouseButton() for collective)
14 
15     Input Parameter:
16 .   draw - the window to be used
17 
18     Output Parameters:
19 +   button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT
20 .   x_user, y_user - user coordinates of location (user may pass in NULL).
21 -   x_phys, y_phys - window coordinates (user may pass in NULL).
22 
23     Level: intermediate
24 
25     Notes:
26     Only processor 0 of the communicator used to create the PetscDraw may call this routine.
27 
28 .seealso: PetscDrawSynchronizedGetMouseButton()
29 @*/
30 PetscErrorCode  PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
31 {
32   PetscErrorCode ierr;
33   PetscBool      isnull;
34 
35   PetscFunctionBegin;
36   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
37   PetscValidPointer(button,2);
38   *button = PETSC_BUTTON_NONE;
39   ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr);
40   if (isnull) PetscFunctionReturn(0);
41   if (!draw->ops->getmousebutton) PetscFunctionReturn(0);
42   ierr = (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);
43   PetscFunctionReturn(0);
44 }
45 
46 #undef __FUNCT__
47 #define __FUNCT__ "PetscDrawSynchronizedGetMouseButton"
48 /*@
49     PetscDrawSynchronizedGetMouseButton - Returns location of mouse and which button was
50     pressed. Waits for button to be pressed.
51 
52     Collective over PetscDraw
53 
54     Input Parameter:
55 .   draw - the window to be used
56 
57     Output Parameters:
58 +   button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT
59 .   x_user, y_user - user coordinates of location (user may pass in NULL).
60 -   x_phys, y_phys - window coordinates (user may pass in NULL).
61 
62     Level: intermediate
63 
64 .seealso: PetscDrawGetMouseButton()
65 @*/
66 PetscErrorCode  PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
67 {
68   PetscReal      bcast[4];
69   PetscErrorCode ierr;
70   PetscMPIInt    rank;
71 
72   PetscFunctionBegin;
73   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
74   PetscValidPointer(button,2);
75 
76   *button = PETSC_BUTTON_NONE;
77   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr);
78 
79   ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
80   if (!rank) {ierr = PetscDrawGetMouseButton(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);}
81   ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
82 
83   ierr = MPI_Bcast((PetscEnum*)button,1,MPIU_ENUM,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
84   if (x_user) bcast[0] = *x_user;
85   if (y_user) bcast[1] = *y_user;
86   if (x_phys) bcast[2] = *x_phys;
87   if (y_phys) bcast[3] = *y_phys;
88   ierr = MPI_Bcast(bcast,4,MPIU_REAL,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
89   if (x_user) *x_user = bcast[0];
90   if (y_user) *y_user = bcast[1];
91   if (x_phys) *x_phys = bcast[2];
92   if (y_phys) *y_phys = bcast[3];
93   PetscFunctionReturn(0);
94 }
95 
96 
97 
98 
99 
100 
101