Изучение кода
Создание плиток
|
| ||||
Изучение кода | |||||
Теперь посмотрим на код функции gp:calculate-Draw-TileRow:
(defun gp:calculate-Draw-TileRow (startPoint TileRadius TileSpace pathWidth pathAngle offsetFromCenter ObjectCreationStyle / HalfWidth TileDiameter ObjectCreationFunction angp90 angm90 firstCenterPt TileCenterPt TileList) (setq HalfWidth (- (/ pathWidth 2.00) TileRadius) Tilespacing (+ (* TileRadius 2.0) TileSpace) TileDiameter (* TileRadius 2.0) angp90 (+ PathAngle (Degrees->Radians 90)) angm90 (- PathAngle (Degrees->Radians 90)) firstCenterPt (polar startPoint angp90 offsetFromCenter) tileCenterPt firstCenterPt ObjectCreationStyle(strcase ObjectCreationStyle) ObjectCreationFunction (cond ((equal ObjectCreationStyle "ACTIVEX") gp:Create_activeX_Circle ) ((equal ObjectCreationStyle "ENTMAKE") gp:Create_entmake_Circle ) ((equal ObjectCreationStyle "COMMAND") gp:Create_command_Circle ) (T (alert (strcat "ObjectCreationStyle in function gp:calculate?Draw?TileRow" "\nis invalid. Contact developer for assistance." "\n ObjectCreationStyle set to ACTIVEX" ) ) setq ObjectCreationStyle "ACTIVEX") ) ) ) ;; Draw the circles to the left of the center. (while (< (distance startPoint tileCenterPt) HalfWidth) ;; Add each tile to the list to return. (setq tileList (cons (ObjectCreationFunction tileCenterPt TileRadius) tileList ) ) ;; Calculate the center point for the next tile. (setq tileCenterPt (polar tileCenterPt angp90 TileSpacing) ) );_ end of while ;; Draw the circles to the right of the center. (setq tileCenterPt (polar firstCenterPt angm90 TileSpacing)) (while (< (distance startPoint tileCenterPt) HalfWidth) ;; Add each tile to the list to return. (setq tileList (cons (ObjectCreationFunction tileCenterPt TileRadius) tileList ) ) ;; Calculate the center point for the next tile. (setq tileCenterPt (polar tileCenterPt angm90 TileSpacing)) );_ end of while ;; Return the list of tiles. tileList ) ;_ end of defun Этот AutoLISP- код реализует описанный выше словесный алгоритм и имеет следующие дополнения: (setq ObjectCreationFunction (cond ((equal ObjectCreationStyle "ACTIVEX") gp:Create_activeX_Circle ) ((equal ObjectCreationStyle "ENTMAKE") gp:Create_entmake_Circle ) ((equal ObjectCreationStyle "COMMAND") gp:Create_command_Circle ) (T (alert (strcat "ObjectCreationStyle in function gp:calculate-Draw-TileRow" "\nis invalid. Contact the developer for assistance." "\n ObjectCreationStyle set to ACTIVEX" ) ;_ end of strcat ) ;_ end of alert (setq ObjectCreationStyle "ACTIVEX") ) ) ;_ end of cond ) ;_ end of setq Вспомним, что плитки (круги) можно строить одним из трех способов: с помощью функций ActiveX, функции entmake и функции command. Переменной ObjectCreationFunction присваивается одна из этих трех функций, в зависимости от параметра ObjectCreationStyle (передаваемого из C:GPath через gp:Calculate-and-Draw-Tiles). Ниже приводятся три функции, как они должны выглядеть в файле gpdraw.lsp: (defun gp:Create_activeX_Circle (center radius) (vla-addCircle *ModelSpace* (vlax-3d-point center) ; convert to ActiveX-compatible 3D point радиус ) ) ;_ end of defun (defun gp:Create_entmake_Circle(center radius) (entmake (list (cons 0 "CIRCLE") (cons 10 center) (cons 40 radius)) ) (vlax-ename->vla-object (entlast)) ) (defun gp:Create_command_Circle(center radius) (command "_CIRCLE" center radius) (vlax-ename->vla-object (entlast)) ) Первая функция строит круг с помощью функции ActiveX и возвращает объект ActiveX. Вторая функция строит круг с помощью функции entmake. Она возвращает имя объекта, преобразованное в объект ActiveX. Третья функция строит круг с помощью функции command. Она также возвращает имя объекта, преобразованное в объект ActiveX. |