Переработка кода программы
Средства отладки Visual LISP
|
| ||||
Переработка кода программы |
| ||||
Теперь, познакомившись с принципом работы ассоциативных списков в AutoLISP, воспользуемся этим типом списка для написания окончательного варианта функции gp:getPointInput. Для этого следует заменить предыдущую версию gp:getPointInput, ранее сохраненную в файле gpmain.lsp, следующим кодом.
Примечание При наборе текста программы в файле gpmain.lsp вручную (а не копированием из имеющегося готового файла) можно сэкономить время, исключив все комментарии (строки, начинающиеся с точки запятой). Однако это не означает, что следует привыкать писать код без комментариев и в дальнейшем! ;;;--------------------------------------------------------------; ;;; Функция: gp:getPointInput ; ;;;--------------------------------------------------------------; ;;; Описание: С помощью этой функции пользователю предлагается выбрать три точки с запятой (;) ;;; points in a drawing, which will determine the ; ;;; path location, direction, and size. ; ;;;--------------------------------------------------------------; ;;; If the user responds to the get functions with valid data, ; ;;; use startPt and endPt to determine the position, length, ; ;;; and angle at which the path is drawn. ; ;;;--------------------------------------------------------------; ;;; Эта функция возвращает список, который состоит из следующих элементов: ; ;;; (10 . Starting Point) ;; List of 3 reals (a point) denoting ; ;;; ;; starting point of garden path. ; ;;; (11 . Ending Point) ;; List of 3 reals (a point) denoting ; ;;; ;; ending point of garden path. ; ;;; (40 . Width) ;; Real number denoting boundary ; ;;; ;; ширина. ; ;;; (41 . Length) ;; Real number denoting boundary ; ;;; ;; длина. ; ;;; (50 . Path Angle) ;; Real number denoting the angle ; ;;; ;; of the path, in radians. ; ;;;--------------------------------------------------------------; (defun gp:getPointInput(/ StartPt EndPt HalfWidth) (if (setq StartPt (getpoint "\nStart point of path: ")) (if (setq EndPt (getpoint StartPt "\nEndpoint of path: ")) (if (setq HalfWidth (getdist EndPt "\nhalf-width of path: ")) ;; if you' ve made it this far, build the association list ;; as documented above. This will be the return value ;; from the function. (list (cons 10 StartPt) (cons 11 EndPt) (cons 40 (* HalfWidth 2.0)) (cons 50 (angle StartPt EndPt)) (cons 41 (distance StartPt EndPt)) ) ) ) ) ) Теперь необходимо обновить основную функцию C:GPath в файле gpmain.lsp. Она должна выглядеть следующим образом: (defun C:GPath (/ gp_PathData) ;; Запрос на ввод: путь к местоположению и ;; 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 (gp:getDialogInput) (progn ;; At this point, you have valid input from the user. ;; Draw the outline, storing the resulting polyline ;; pointer in the variable called PolylineName. (setq PolylineName (gp:drawOutline)) (princ "\nThe gp:drawOutline function returned <") (princ PolylineName) (princ ">") (Alert "Congratulations - your program is complete!") ) ;_ 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 При копировании и вставке кода перед описанием функции C:GPath: следует добавить следующий заголовок: ;;;**************************************************************; ;;; Функция: C:GPath - основная функция для построения парковой дорожки ; ;;;--------------------------------------------------------------; ;;; Описание: Это основная функция для построения парковой дорожки. It is a ; ;;; C: функция означает, что она преобразуется в ; ;;; команда AutoCAD именуемая GPATH. This function ; ;;; determines the overall flow of the garden path ; ;;; program. ; ;;;**************************************************************; ;;; В переменной gp_PathData содержится ассоциативный список форм: ; ;;; (10 . Starting Point) - List of 3 reals (a point) denoting ; ;;; starting point of the garden path. ; ;;; (11 . Ending Point) - List of 3 reals (a point) denoting ; ;;; endpoint of the garden path. ; ;;; (40 . Width) - Real number denoting boundary ; ;;; ширина. ; ;;; (41 . Length) - Real number denoting boundary ; ;;; длина. ; ;;; (50 . Path Angle) - Real number denoting the angle of ; ;;; the path, in radians. ; ;;; (42 . Tile Size) - Real number denoting the size ; ;;; (radius) of the garden path tiles. ; ;;; (43 . Tile Offset) - Spacing of tiles, border to border. ; ;;; ( 3 . Object Creation Style) ; ;;; - Object creation style indicates how ; ;;; the tiles are to be drawn. Элемент ; ;;; expected value is a string and one ; ;;; one of three values (string case ; ;;; не важен): ; ;;; "ActiveX" ; ;;; "Entmake" ; ;;; "Command" ; ;;; ( 4 . Polyline Border Style) ; ;;; - Polyline border style determines ; ;;; the polyline type to be used for ; ;;; path boundary. The expected value ; ;;; one of the following (string case is; ;;; не важна): ; ;;; "Pline" ; ;;; "Light" ; ;;;**************************************************************; Для проверки переработанного кодаЕсли при выполнении программы возникли ошибки, следует попытаться их исправить и запустить программу снова. Если успешного выполнения программы не удается добиться даже после нескольких попыток, можно скопировать правильный код из папки Tutorial\VisualLISP\Lesson2. |