⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gppoly.lsp

📁 Autocad-2005-简体中文-解密版.zip
💻 LSP
📖 第 1 页 / 共 2 页
字号:
;;;     Function: gp:FindMovedPoint                                    ;
;;;--------------------------------------------------------------------;
;;;  Description: This function's responsibility is to find the        ;
;;;               specific polyline border corner point that moved by  ;
;;;               comparing the presentPoints (the corner points after ;
;;;               the user has moved one of them) with the keyed point ;
;;;               list representing the previous configuration of the  ;
;;;               path border.                                         ;
;;;                                                                    ;
;;;   Arguments:  keyListToLookFor = list of keyindexes '( 12 13 14 15);
;;;               PresentPoints    = a list of points to examine       ;
;;;               KeyedList        = a list comprised of consed key    ;
;;;                                  values and points.                ;
;;;--------------------------------------------------------------------;

(defun gp:FindMovedPoint (keyListToLookFor PresentPoints KeyedList /
			  keyliststatus	missingkey movedpoint result
			  returnvalue)
  (setq	result (apply 'append
		      (mapcar '(lambda (PointToLookFor)
				 ;; since Findpoint only returns a value when found
				 ;; lets test the result. If its nil we'll place

				 (if (setq ReturnValue
					    (gp:FindPointInList PointToLookFor KeyedList)
				     ) ;_ end of setq
				   ReturnValue
				   ;; the function above returned
				   ;; something like ( (15 4.05253 6.28481) )
				   ;; the structure above is a list within a list

				   ;; It failed (returned nil)
				   ;; So we return a new value using the 
				   (list (cons nil PointToLookFor))
				 ) ;_ end of if
			       ) ;_ end of lambda
			      PresentPoints
		      ) ;_ end of mapcar
	       ) ;_ end of apply
  ) ;_ end of setq

  ;; The expression above returned something like this:
  ;; ((12 #.# #.#) (14 #.# #.#) (15 #.# #.#))
  
  ;; Now run a test to find out which assoc key is missing
  (setq	KeylistStatus
	 (mapcar '(lambda (IndexKey)
		    (if	(assoc IndexKey result)
		      (list T (assoc IndexKey result))
		      (list nil IndexKey)
		    ) ;_ end of if
		  ) ;_ end of lambda
		 keyListToLookFor
	 ) ;_ end of mapcar
  ) ;_ end of setq

  ;; The expression above returned something like this:
  ;; ((T (12 #.# #.#))  (nil 13)  (T (14 #.# #.#))   (T (15 #.# #.#)))

  ;; Now return just the key value for the missing point
  (setq	MissingKey
	 (cadr
	   (car
	     (vl-remove-if	'(lambda (argument)
			   (not (null (car Argument)))
			 ) ;_ end of lambda
			KeylistStatus
	     ) ;_ end of vl-remove-if

	   ) ;_ end of car
	 ) ;_ end of cadr
  ) ;_ end of setq

  ;; the expression above returned 13

  ;; Now, using the key, get the point that moved
  (setq	MovedPoint (cdar
	     ;; vl-remove-if-not in this case is testing for the car
	     ;; to be anything that is not nil. 
		     (vl-remove-if-not
		       '(lambda	(argument)
			  (null (car Argument))
			  ) ;_ end of lambda
		       Result
		       ) ;_ end of vl-remove-if-not
	 ) ;_ end of cdar
  ) ;_ end of setq

  ;; The expression above returned a point, something like this:
  ;;     (##.##  ##.##)

  ;; Just incase we end up with a 2D list, add the current elevation
  ;; to turn it into a 3D point
  (if (< (length MovedPoint) 3)
    ;; Princ we'll fix it here
    (setq MovedPoint
	   (list (car MovedPoint)
		 (cadr MovedPoint)
		 (getvar "elevation")
	   ) ;_ end of list
    ) ;_ end of setq
  ) ;_ end of if

  ;; This is the last evaluation that will be returned by this function.
  ;; This will now return the missing key with the moved point
  ;; something like: (13 ##.##  ##.##) 
  (cons	MissingKey
	MovedPoint
  ) ;_ end of cons
) ;_ end of defun



;;;--------------------------------------------------------------------;
;;;     Function: gp:RedefinePolyBorder                                ;
;;;--------------------------------------------------------------------;
;;;  Description:  This function is responsible for redefining the     ;
;;;                garden path polyline border, and returning the new  ;
;;;                reactor data which will be placed in the reactor    ;
;;;                data properties.                                    ;
;;;--------------------------------------------------------------------;
(defun gp:RedefinePolyBorder (PresentPoints Reactordata	/
			     KeyedList MovedKeyPoint NewKeyedList)
  ;; The keyedList contains information on the previous configuration
  ;; of the polyline.  This information is stored in the reactor data,
  ;; and was attached immediately after the polyline was created.
  (setq	KeyedList (list	(assoc 12 reactorData)
			(assoc 15 reactorData)
			(assoc 13 reactorData)
			(assoc 14 reactorData)
		  ) ;_ end of list
  ) ;_ end of setq
  
  ;; Since we know one of the points has moved we need to check
  ;; the points supplied against the saved points in reactorData
  ;; those points keys will be 12 13 14 15. We will test every point in
  ;; the supplied present point list and test it against every point
  ;; in the presentPoints list, which contains the 12 13 14 15 point
  ;; lists from the current (modified by the user) polyline configuration.
  ;; This way we can check for which point failed (i.e., did not match.)

  ;; The history of 12 13 14 15
  ;; StartingPoint
  ;;	(12 . BottomStartingPoint )
  ;;	(15 . TopStartingPoint )
  ;; EndingPoint 
  ;;	(13 .  BottomEndingPoint )
  ;;	(14 . TopEndingPoint )
  (setq	MovedKeyPoint
	 (gp:FindMovedPoint
	   '(12 13 14 15)
	   PresentPoints
	   KeyedList
	 ) ;_ end of gp:FindMovedPoint
  ) ;_ end of setq

  ;; We use the path angle to determine where and what to do
  (setq NewKeyedList (gp:recalcPolyCorners MovedKeyPoint KeyedList))

  ;; Now that we have the keyed list, all 12 13 14 15 keyindeces
  ;; are updated.  We need to update the reactor data  with the
  ;; new begining ending points and other values. 
  ;; We will now use foreach since we do not need the entire
  ;; reactordata structure, only its final result

  (foreach NewItem NewKeyedList
    (setq reactorData
	   (subst NewItem
		  (assoc (car newItem) reactorData)
		  reactorData
	   ) ;_ end of subst
    ) ;_ end of setq
  ) ;_ end of foreach

  ;; Now that we have changed the value of reactorData
  ;; with the returning values supplied by gp:recalcPolyCorners,
  ;; we can update other important information in reactorData.

  ;; Take care of placing new starting point, ending point, Width,
  ;; Path Length and Path Angle.
  (setq
    ;; Starting Point
    reactorData
		(subst (cons 10
			     (midpoint (cdr (assoc 15 reactorData))
				       (cdr (assoc 12 reactorData))
			     ) ;_ end of midpoint
		       ) ;_ end of cons
		       (assoc 10 reactorData)
		       reactorData
		) ;_ end of subst
    ;; Ending Point	
    reactorData	(subst (cons 11
			     (midpoint (cdr (assoc 14 reactorData))
				       (cdr (assoc 13 reactorData))
			     ) ;_ end of midpoint
		       ) ;_ end of cons
		       (assoc 11 reactorData)
		       reactorData
		) ;_ end of subst
    ;; Width 
    reactorData
		(subst (cons 40
			     (distance (cdr (assoc 14 reactorData))
				       (cdr (assoc 13 reactorData))
			     ) ;_ end of distance
		       ) ;_ end of cons
		       (assoc 40 reactorData)
		       reactorData
		) ;_ end of subst
    ;; pathLength
    reactorData
		(subst (cons 41
			     (distance (cdr (assoc 10 reactorData))
				       (cdr (assoc 11 reactorData))
			     ) ;_ end of distance
		       ) ;_ end of cons
		       (assoc 41 reactorData)
		       reactorData
		) ;_ end of subst
    ;; PathAngle
    reactorData
		(subst (cons 50
			     (angle (cdr (assoc 10 reactorData))
				    (cdr (assoc 11 reactorData))
			     ) ;_ end of angle
		       ) ;_ end of cons
		       (assoc 50 reactorData)
		       reactorData
		) ;_ end of subst
  ) ;_ end of setq
  reactorData				; return the updated reactor data
) ;_ end of defun


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -