Sei sulla pagina 1di 17

XXXVIII CILAMCE

Ibero-Latin American Congress on Computational Methods in Engineering

DEVELOPMENT OF A CLASS IN THE CONTEXT OF OOP FOR


GENERIC MANAGEMENT OF MOUSE EVENTS IN A CANVAS IN
THE MATLAB ENVIRONMENT

Emersson Duvan Torres


Luiz Fernando Martha
Emouse Class
This is an OOP abstract class, developed in MATLAB, to facilitate the development of
applications that handle mouse events on canvas (axes: the drawing area of a GUI
application in MATLAB).
This abstract class presents, in addition to the constructor method, 4 private concrete
methods (implemented) and 3 abstract methods that must be implemented by the
client user.
Its use is achieved by creating a client subclass that inherits its properties and
implements the 3 abstract methods.
Advantage:
• The hardest part to deal with mouse events in canvas is treated in the concrete
methods of the abstract class Emouse.
• The client subclass just requires to treat the specific procedures of its application.

2
MATLAB l figure and axes
Figure and Axes Objects axes object
figure object • CurrentPoint: location of mouse
pointer on the axes object.
• SelectionType: provide
information about the last mouse
button pressed on the figure. figure object (window)
• CurrentPoint: location of mouse
pointer on the figure object.
axes object (canvas)

• WindowButtonDownFcn: mouse
button press callback function.
• WindowButtonMotionFcn:
mouse motion callback function.
• WindowButtonUpFcn: mouse
button release callback function.
3
Emouse Class l Attributes
Emouse Class Attributes
• dialog: handle to the target figure object (window) associated to mouse events.

• canvas: handle to the initial axes (canvas) of the target figure associated to mouse
events.

• mouseButtonMode: button mouse states, “up” (release) or “down” (pressed).

• whichMouseButton: “none”, “left”, “right”, “center” or “double click” at button


mouse down.

• currentPosition: x and y coordinates of the current pointer position.


4
Emouse Class l Methods
Private Concrete Methods
• Constructor method: intended to initialize an object of the Emouse class. This
method associates the mouse button down, mouse move, and mouse button up
events on the target figure with the private eButtonDown, eMouseMove, and
eButtonUp methods, respectively. Its input arguments are:
- dlg: handle to the target figure object (dialog).
- cnvs: handle to the initial axes (canvas) of the target figure.

• clean: initializes property values of an Emouse object.

5
Emouse Class l Methods
Private Concrete Methods
• eButtonDown: is a callback function associated with mouse button down event on
the target canvas. It finds, in the list of canvases of the target figure window, the
canvas in which the button down position is located. Also it determines which button
was pressed, updates the whichMouseButton property, sets the mouseButtonMode
property to down, sets the current position to the mouse button down position and
calls the abstract downAction method.
• eMouseMove: is a callback function associated with mouse move event on the target
window. It sets the current position to the current mouse position on the target
canvas and calls the abstract moveAction method.
• eButtonUp: is a callback function associated with mouse button up events on the
target window. It sets the mouseButtonMode property to up, sets the current
position to the mouse button up position on the target canvas, and calls the abstract
upAction method.
6
Emouse Class l Methods
Abstract Methods
The client user must implement the abstract methods:

• downAction: with the procedures to be performed when the


user presses a mouse button.

• moveAction: with the procedures to be performed when the


user moves the mouse.

• upAction: with the procedures to be performed when the


user releases the mouse button that was pressed.

7
Emouse Class l Methods
Emouse Methods

Constructor method Emouse

Concrete methods mouseMove eButtonDown eButtonUp

Abstract methods moveAction downAction upAction

8
Emouse Class l Use
Use of the Emouse class
Create a subclass that inherits from the
Emouse class.

9
Emouse Class l Use
Use of the Emouse class
Create a subclass that inherits from the
Emouse class.

Implement new attributes in the


properties of this subclass.

10
Emouse Class l Use
Use of the Emouse class
Create a subclass that inherits from the
Emouse class.

Implement new attributes in the


properties of this subclass.

Implement a constructor method.

11
Emouse Class l Use
Use of the Emouse class
Create a subclass that inherits from the
Emouse class.

Implement new attributes in the


properties of this subclass.

Implement a constructor method.

Implement the abstract methods of the


Emouse class in this subclass.

12
Emouse Class l Use
Use of the Emouse class
Create a subclass that inherits from the
Emouse class.

Implement new attributes in the


properties of this subclass.

Implement a constructor method.

Implement the abstract methods of the


Emouse class in this subclass.

Create an object of the new subclass


and providing a figure object and an
axes object. 13
Emouse Class l Apps developed
e-dles2D
Draw Linear Elements Structure 2D,
it allows to draw frame structures
in 2D

14
Emouse Class l Apps developed
e-Mohr2
Mohr's circle for plane stress state,
it allows to demonstrate the
functioning of the Mohr circle for
stress state.

15
Emouse Class l Conclusions
Conclusions
A class in the context of OOP for generic management of mouse events on a canvas in the
MATLAB environment was developed.
Using the Emouse class, two engineering apps, were developed in the MATLAB environment in
the context of OOP. The development of these apps highlights the generic property of this class.
The OOP context provides a simple and reusable maintenance code that favors the creation of
new functionalities.
The developed class can be used at the implementation of MATLAB apps, in the context of OOP,
besides visualization, creation, and manipulation of models, aiming to be educational graphic-
interactive tools. As a result of the mouse interaction these processes become quite better
comprehended.
The proposal for future work includes: implementing the events with the mouse scroll button;
Implement mouse events that consider three dimensions; Create a more complete version of
the e-dles2D app, where can be set boundary conditions and geometric and constitutive
properties of the elements.
The future work has a wider view, because the Emouse class is a potential tool to develop, in
the MATLAB environment, educational graphic-interactive softwares.

16
XXXVIII CILAMCE
Ibero-Latin American Congress on Computational Methods in Engineering

Questions?

Potrebbero piacerti anche