15c6c1daeSBarry Smith 25c6c1daeSBarry Smith /* 35c6c1daeSBarry Smith Provides the calling sequences for all the basic PetscDraw routines. 45c6c1daeSBarry Smith */ 5af0996ceSBarry Smith #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 65c6c1daeSBarry Smith 75c6c1daeSBarry Smith #undef __FUNCT__ 85c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawGetMouseButton" 95c6c1daeSBarry Smith /*@ 105c6c1daeSBarry Smith PetscDrawGetMouseButton - Returns location of mouse and which button was 115c6c1daeSBarry Smith pressed. Waits for button to be pressed. 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith Not collective (Use PetscDrawSynchronizedGetMouseButton() for collective) 145c6c1daeSBarry Smith 155c6c1daeSBarry Smith Input Parameter: 165c6c1daeSBarry Smith . draw - the window to be used 175c6c1daeSBarry Smith 185c6c1daeSBarry Smith Output Parameters: 199f80f0efSLisandro Dalcin + button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT, PETSC_BUTTON_WHEEL_UP, PETSC_BUTTON_WHEEL_DOWN 20e118a51fSLisandro Dalcin . x_user, y_user - user coordinates of location (user may pass in NULL). 21e118a51fSLisandro Dalcin - x_phys, y_phys - window coordinates (user may pass in NULL). 225c6c1daeSBarry Smith 235c6c1daeSBarry Smith Level: intermediate 245c6c1daeSBarry Smith 255c6c1daeSBarry Smith Notes: 265c6c1daeSBarry Smith Only processor 0 of the communicator used to create the PetscDraw may call this routine. 275c6c1daeSBarry Smith 285c6c1daeSBarry Smith .seealso: PetscDrawSynchronizedGetMouseButton() 295c6c1daeSBarry Smith @*/ 305c6c1daeSBarry Smith PetscErrorCode PetscDrawGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys) 315c6c1daeSBarry Smith { 325c6c1daeSBarry Smith PetscErrorCode ierr; 335c6c1daeSBarry Smith PetscBool isnull; 345c6c1daeSBarry Smith 355c6c1daeSBarry Smith PetscFunctionBegin; 365c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 37e118a51fSLisandro Dalcin PetscValidPointer(button,2); 385c6c1daeSBarry Smith *button = PETSC_BUTTON_NONE; 395c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr); 405c6c1daeSBarry Smith if (isnull) PetscFunctionReturn(0); 415c6c1daeSBarry Smith if (!draw->ops->getmousebutton) PetscFunctionReturn(0); 425c6c1daeSBarry Smith ierr = (*draw->ops->getmousebutton)(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr); 435c6c1daeSBarry Smith PetscFunctionReturn(0); 445c6c1daeSBarry Smith } 455c6c1daeSBarry Smith 465c6c1daeSBarry Smith #undef __FUNCT__ 475c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSynchronizedGetMouseButton" 485c6c1daeSBarry Smith /*@ 495c6c1daeSBarry Smith PetscDrawSynchronizedGetMouseButton - Returns location of mouse and which button was 505c6c1daeSBarry Smith pressed. Waits for button to be pressed. 515c6c1daeSBarry Smith 525c6c1daeSBarry Smith Collective over PetscDraw 535c6c1daeSBarry Smith 545c6c1daeSBarry Smith Input Parameter: 555c6c1daeSBarry Smith . draw - the window to be used 565c6c1daeSBarry Smith 575c6c1daeSBarry Smith Output Parameters: 589f80f0efSLisandro Dalcin + button - one of PETSC_BUTTON_LEFT, PETSC_BUTTON_CENTER, PETSC_BUTTON_RIGHT, PETSC_BUTTON_WHEEL_UP, PETSC_BUTTON_WHEEL_DOWN 59e118a51fSLisandro Dalcin . x_user, y_user - user coordinates of location (user may pass in NULL). 60e118a51fSLisandro Dalcin - x_phys, y_phys - window coordinates (user may pass in NULL). 615c6c1daeSBarry Smith 625c6c1daeSBarry Smith Level: intermediate 635c6c1daeSBarry Smith 645c6c1daeSBarry Smith .seealso: PetscDrawGetMouseButton() 655c6c1daeSBarry Smith @*/ 665c6c1daeSBarry Smith PetscErrorCode PetscDrawSynchronizedGetMouseButton(PetscDraw draw,PetscDrawButton *button,PetscReal *x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys) 675c6c1daeSBarry Smith { 685c6c1daeSBarry Smith PetscReal bcast[4]; 695c6c1daeSBarry Smith PetscErrorCode ierr; 705c6c1daeSBarry Smith PetscMPIInt rank; 715c6c1daeSBarry Smith 725c6c1daeSBarry Smith PetscFunctionBegin; 735c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 74e118a51fSLisandro Dalcin PetscValidPointer(button,2); 75e118a51fSLisandro Dalcin 76e118a51fSLisandro Dalcin *button = PETSC_BUTTON_NONE; 77ce94432eSBarry Smith ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr); 78e118a51fSLisandro Dalcin 79e118a51fSLisandro Dalcin ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); 80e118a51fSLisandro Dalcin if (!rank) {ierr = PetscDrawGetMouseButton(draw,button,x_user,y_user,x_phys,y_phys);CHKERRQ(ierr);} 81e118a51fSLisandro Dalcin ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); 82*d5eca3faSLisandro Dalcin ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); 83e118a51fSLisandro Dalcin 84ce94432eSBarry Smith ierr = MPI_Bcast((PetscEnum*)button,1,MPIU_ENUM,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr); 855c6c1daeSBarry Smith if (x_user) bcast[0] = *x_user; 865c6c1daeSBarry Smith if (y_user) bcast[1] = *y_user; 875c6c1daeSBarry Smith if (x_phys) bcast[2] = *x_phys; 885c6c1daeSBarry Smith if (y_phys) bcast[3] = *y_phys; 89ce94432eSBarry Smith ierr = MPI_Bcast(bcast,4,MPIU_REAL,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr); 905c6c1daeSBarry Smith if (x_user) *x_user = bcast[0]; 915c6c1daeSBarry Smith if (y_user) *y_user = bcast[1]; 925c6c1daeSBarry Smith if (x_phys) *x_phys = bcast[2]; 935c6c1daeSBarry Smith if (y_phys) *y_phys = bcast[3]; 945c6c1daeSBarry Smith PetscFunctionReturn(0); 955c6c1daeSBarry Smith } 965c6c1daeSBarry Smith 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith 102