Обновление функции C:GPath
Использование реакторов
|
| ||||
Обновление функции C:GPath |
| ||||
Обновим функцию C:GPath, создав в ней реакторы
Для создания реактора в C:GPath(defun C:GPath (/ gp_PathData gp_dialogResults PolylineName tileList ) (setvar "OSMODE" 0) ;; Отключают объектную привязку ;| ;; Lesson 6 - добавление фиктивного реактора команды в AutoCAD ;; However, it would be undesirable to react to every ;; drawing of a circle should the COMMAND tile creation ;; method be chosen by the user. So, disable the ;; *commandReactor* in case it exists. |; (if *commandReactor* (progn (setq *commandReactor* nil) (vlr-remove-all :VLR-Command-Reactor) ) ) ;; Запрос на ввод: путь к местоположению и ;; direction, then for path parameters. Continue only if you ;; have valid input. Store the data in gp_PathData. (if (setq gp_PathData (gp:getPointInput)) (if (setq gp_dialogResults (gp:getDialogInput (cdr (assoc 40 gp_PathData)) ) ;_ end of gp:getDialogInput ) ;_ end of setq (progn ;; Now take the results of gp:getPointInput and append this to ;; добавленная информация передается с помощью функции gp:getDialogInput (setq gp_PathData (append gp_PathData gp_DialogResults)) ;; На этом этапе все данные, указанные пользователем, введены ;; Draw the outline, storing the resulting polyline "pointer" ;; в переменную, именуемую PolylineName (setq PolylineName (gp:drawOutline gp_PathData)) ;; Next, it is time to draw the tiles within the boundary. ;; The gp_tileList contains a list of the object pointers for ;; the tiles. By counting up the number of points (using the ;; length function), we can print out the results of how many ;; tiles were drawn. (princ "\nThe path required ") (princ (длина (setq tileList (gp:Calculate-and-Draw-Tiles gp_PathData)) ) ;_ end of length ) ;_ end of princ (princ " tiles.") ;; Добавляют список указателей к плиткам (возвращаемый ;; gp:Calculate-and-Draw-Tiles) to gp_PathData. This will ;; be stored in the reactor data for the reactor attached ;; to the boundary polyline. With this data, the polyline ;; "knows" what tiles (circles) belong to it. (setq gp_PathData (append (list (cons 100 tileList)) ; all the tiles gp_PathData ) ;_ end of append ) ;_ end of setq ;; Прежде чем назначить данные реактора объекту, рассмотрим ;; функцию vlr-object-reactor ;; vlr-object-reactor has the following arguments: ;; (vlr-object-reactor owner’s data callbacks) ;; The callbacks Argument is a list comprised ;; '(event_name . функция_отклика) ;; ;; For this exercise we will use all arguments ;; связанные с реактором объекта vlr-object-reactor ;; These reactor functions will execute only if ;; полилиния будет изменена или удалена в PolylineName (vlr-object-reactor ;; The first argument for vlr-object-reactor is ;; the "Owner’s List" argument. This is where to ;; place the object to be associated with the ;; reactor. In this case, it is the vlaObject ;; stored in PolylineName. (list PolylineName) ;; The second argument contains the data for the path gp_PathData ;; The third argument is the list of specific reactor ;; типов реакторов, которые требуется использовать ' ( ;; реактор, вызываемый при изменении объекта (:vlr-modified . gp:outline-changed) ;; реактор, вызываемый при удалении объекта (:vlr-erased . gp:outline-erased) ) ) ;_ end of vlr-object-reactor ;; Next, register a command reactor to adjust the polyline ;; по завершении команды изменения (if (not *commandReactor*) (setq *commandReactor* (VLR-Command-Reactor nil ; No data is associated with the command reactor '( (:vlr-commandWillStart . gp:command-will-start) (:vlr-commandEnded . gp:command-ended) ) ) ;_ end of vlr-command-reactor ) ) ;; The following code removes all reactors when the drawing is ;; closed. This is extremely important!!!!!!!!! ;; Без этого уведомления может произойти аварийное завершение работы AutoCAD! (if (not *DrawingReactor*) (setq *DrawingReactor* (VLR-DWG-Reactor nil ; No data is associated with the drawing reactor '((:vlr-beginClose . gp:clean-all-reactors) ) ) ;_ end of vlr-DWG-reactor ) ) ) ;_ end of progn (princ "\nFunction cancelled.") ) ;_ end of if (princ "\nIncomplete information to draw a boundary.") ) ;_ end of if (princ) ; exit quietly ) ;_ end of defun ;;; Display a message to let the user know the command name. (princ "\nType GPATH to draw a garden path.") (princ) |