#|

Features

Note: This is an example file showing concepts of the Integration Kit. The code itself is not supported and will never be supported.
|#


(in-package :EXAMPLES)
(use-package :OLI)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(sd-defdialog 'MOVE_5
  :dialog-title "Move 5"
  :variables
  '((part-name)
    (feat-name)
    (translation)
    (moved)
    (JJ_FACE :value-type :face
	     :title "Face"
	     :prompt-text "Identify FACE."
	     :check-function is-planar-face
	     :after-input (after-face jj_face))
    (NEXT :push-action (move-it)))
  :local-functions
  '((is-planar-face (f)
     (if (sd-plane-p (sd-inq-geo-props f)) :ok :error))
    (after-face (f)
     (when
      (and part-name feat-name)
      (sd-call-cmds (remove_feature :full_name
				    :start_name part-name
				    :feature feat-name
				    :end_name)))
     (multiple-value-setq (part-name feat-name) (jb-sel_item-to-feature f))
     (setf translation
	   (sd-vec-scale (sd-plane-normal (sd-inq-geo-props f)) 5)))
    (move-it ()
     (setf moved
      (sd-call-cmds (move :nocheck :by_feature
			  :full_name
			  :start_name part-name
			  :feature feat-name
			  :end_name
			  :transformation :translate translation)
		    :success t))))
  :start-variable 'jj_face
  :ok-action
  '(unless moved (move-it))
  :cleanup-action
  '(sd-call-cmds (remove_feature :full_name
				 :start_name part-name
				 :feature feat-name
				 :end_name)
		 :failure nil))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun jb-sel_item-to-feature (s)
  (let*
   ((part-name (sd-inq-obj-pathname s))
    (part (sd-pathname-to-obj part-name))
    (all-feat (sd-inq-part-named-features part))
    (feat-name))
   (do*
    ((i 1 (incf i)))
    ((not (member (format nil "feat~A" i) all-feat :test #'sd-string=)) 
     (setf feat-name (format nil "feat~A" i))))
   (sd-call-cmds (define_feature :selection s :name feat-name))
   (values part-name feat-name)))


;;