Events and methods of the command handler |
Creation of a copy of object: Command handler is carried out automatically by Applied task object in GetAction method at receiving the corresponding command. Class, derivative from TPanAction, corresponds to Command handler object. For installing conformity between the identifier of the command and its handler, the list of handlers in GetAction method of the task is filled. For example: // Execution of commands by means of a handler // CM_MED_MOVEOBJECT - identifier of the command; // TMoveObject - a class derived from TPanAction. // IDN_HLP_MOVEOBJECT - the identifier of Help section, reaction on F1. SeekAction (comid, run) { CheckAction (CM_MED_MOVEOBJECT,TMoveObject,IDN_HLP_MOVEOBJECT); CheckAction (CM_MED_CREATEOBJECT,TCreateObject,IDN_HLP_CREATEOBJECT); //... } At receipt of the command with identifier CM_MED_MOVEOBJECT the constructor of TMoveObject class derived from TPanAction class will be automatically called. Constructor of a class should not carry out any actions, except for initialization of a class variables. After creation of the constructor of a class Handler of the command the system checks presence of an active handler of the command. If this is available, the system asks - whether it can be completed. For this purpose the method of handler CanClose is called. If the active handler cannot be completed, the destructor of again created handler is called. If the active handler is authorized for deleting, after an execution of its destructor the Setup method of a created handler is called. Since this moment the handler is active and can carry out any actions above an electronic map. If the handler of the command is intended for processing separate objects of a map, then at a call of Setup method the inquiry of the current selected object can be executed. IsObjectSelected method of TPanWindow class is applied for this purpose. This method returns the identifier (HOBJ) of the selected object. If the object is not selected, the zero comes back. If the user of system will choose new object, SelectObject event will be generated. The handler can forbid a choice of objects by their characteristics or based on a current status of processing of the beforehand chosen object. For this purpose events are used: CanSelectObject (whether it is possible to choose objects on a map) and CanSelectThisObject (whether it is possible to choose concrete object). Application of the given events is transparent for the user. He should not choose repeatedly object in a point if the top object on the image of a map is rejected by a handler. The system will automatically offer the next object, accessible on a map (or object on a following map in the given point). For a compulsory selection of object on a map (for example, the object corresponding to current record of the table of a database) the SetSelectObject method of TPanWindow class is applied. TPanWindow class is accessible to a handler through MapWindow variable-index. At work of the user with the mouse and the keyboard the following events in a handler of the command are generated: KeyDown - the key of the keyboard is pressed; LeftDown - the left button of the mouse is pressed; LeftUp - the left button of the mouse is released; Move - moving of the mouse cursor on a map window; RightDown - the right button of the mouse is pressed; RightUp - the right button of the mouse is released; CallRightMenu - a pop-up menu is called by pressing the right mouse button, the handler can add items of the menu for current operation; Commit - an execution of current operation (not a handler!) is completed, it is generated at double click of the left mouse button, at pressing the left and right button of the mouse, at a use of a combination of keys CTRL-ENTER, at a choice of corresponding menu item, etc.; Revert - an execution of current operation (not a handler!) is cancelled, it is generated by pressing CTRL key and the right mouse button, at a choice of corresponding menu item, etc.; Paint - repainting of a map is executed, the handler can paint on a map; ResetMessage - it is required to reshow the comment to current operation in an information ruler; ChangeData - the notice about any change of the contents of data of an electronic map (the user maps, rasters, matrixes) if data above whom operation was carried out, became closed - the handler should interrupt operation; At reception of event the handler can use any methods of classes: TPanTask, TPanWindow and own for an execution of demanded operation. To request the coordinates of a current point the following methods can be used: GetPicturePoint - to request coordinates in system of the image in pixels; GetPlanePoint - to request coordinates in rectangular local system in meters; GetGeoPoint - to request coordinates in geographical system in radians, it is admissible, if the map supports geographical coordinates; IsGeoSupported - check of support of geographical coordinates. At reception of Revert event the handler should cancel selection of object (SetSelectObject (0) method of TPanWindow class). If the selected object is not present, the handler can call a method finishing its execution - Close (with query about the sanction) or Quit (unconditional end). As a rule, by repeated pressing the button of the panel it is released and a handler is completed (Close method). But in some tasks it is more convenient to restart the handler anew by repeated pressing, preliminary having finished the handler by Close method. For example, so the creation of objects on a map is realized when the kind of object is chosen from the corresponding dialogue. For change of a kind of object enough to press repeatedly the button of the panel. If in dialogue of a choice of a kind of object to press "Cancel" or to press other button on panel, or to use a combination of keys CTRL-C, etc., - that the handler will be completed without restart. For realization of such scheme of work it is necessary to redefine CanRestartByButton method that it returned nonzero value. For the execution of operations above data of an electronic map the functions of MAPAPI interface should be used. For identification of a processed map the variable of class HMap (HMAP type) is used. For storage of identifiers of objects, the user maps, the raster and matrix data into handlers classes the necessary variables add at a stage of their development. The Description of TPanAction class is contained in PANACT.H file, realization - in PANTASK.CPP file. Files are located in a subdirectory \SDK \PANTASK of that directory where Panorama system is installed.
|