﻿; -*-Lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Description:  customization for MoldDesignAdvisor
; Language:     Lisp
; Package:      MOLD-UI
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package :mold-ui)

;;
;; Function 
;; define-scale-defaults (name type &key display_name
;;                                       (global_scale 1)
;;                                       (x_scale 1) (y_scale 1) (z_scale 1))
;;
;; Define default parameter for scale type and scale parameter in scale_3d dialog.
;;
;; Parameter description:
;; 
;;   name [STRING} - entry in range definition of variable default_values, is
;;                   converted into a keyword
;;   type [:isotropic or :anisotropic]
;;   display_name [STRING] - name which is displayed in the range definition of
;;                           variable default_values
;;   global_scale [NUMBER] - scale parameter for isotropic scaling (default 1)
;;   x_scale [NUMBER] - scale parameter for anisotropic scaling (default 1)
;;   y_scale
;;   z_scale 
;;

;; Example:
;;
;;(define-scale-defaults "Mat1"
;;  :isotropic
;;  :display_name "Material1"
;;  :global_scale 1.2
;;  )
;;
;;(define-scale-defaults "Mat2"
;;  :anisotropic
;;  :display_name "Material2"
;;  :x_scale 1.1
;;  :y_scale 1.2
;;  :z_scale 1.1
;;  )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Create a User Defined Geometric Feature
;; 
;; 1. How does it work?
;; 
;; The programm loads a tool part into the OneSpaceDesigner - through either specifying a 
;; package file or invoking a user defined function - and pastes the faces of the loaded 
;; tool part to the basic mold part. The tool part could be a face part or a solid part. 
;; If it is a solid part, the user will later be asked to specify the open faces on the 
;; tool part for doing the PASTE operation.
;; 
;; 2. What should be done by the user?
;; 
;; The user should register the plastic feature before use. A registration is done in 
;; following steps:
;; a) If the tool part is loaded through a function, the function should be defined in 
;;    LISP at first. 
;; b) The following function is called for the registration:
;;        register-load-plastic-feature (name &key categories
;;				                   load-tool-func 
;;				                   dialog-image
;;				                   browser-image
;;				                   package-file)  
;;    Input parameters:
;;      name             a string which specifies the name of the feature being defined
;;      :categories      a string or a list of strings which specify in which category
;;                       the feature should be shown in the Plastic Feature Browser
;;      :package-file    the package file of the tool part in string, if the tool part
;;                       is saved in a package file in the customization directory:
;;                       sd_customize/MoldDesignAdvisor/user_geometry
;;      :tools-file      the package file of the tools in string, if the tools 
;;                       are saved in a package file in the customization directory:
;;                       sd_customize/MoldDesignAdvisor/user_geometry (optional)
;;      :description     an arbitrary string containing additional information (optional)
;;      :load-tool-func  a function name in string, which specifies the function to load 
;;                       the tool part for PASTE, if :package-file is NOT specified (!).
;;                       NIL should be returned when errors occur.  
;;      :dialog-image    the image filename of the tool part in string (size: about 
;;                       160x160). This is a optional specification. The image will be 
;;                       shown in the feature dialog, and the file should be stored in 
;;                       the customization directory: 
;;                       sd_customize/MoldDesignAdvisor/user_geometry
;;      :browser-image   an image filename in string (size: about 50x50). This is a 
;;                       optional specification. The image will be shown in the Plastic 
;;                       Feature Browser. It should also be stored in the customization 
;;                       directory:
;;                       sd_customize/MoldDesignAdvisor/user_geometry
;;
;; Examples:
;; =========
;; A. Register a user defined geometric feature whose tool part is a solid part. The tool 
;;    part will be loaded through specifying :package-file 
;;   
(register-load-plastic-feature "Boss_Solid-Part"  
                               :categories "Demo Parts" 
                               :package-file "ugeo_solid_boss.pkg"
                               :dialog-image "ugeo_solid_boss.xpm"
                               :description "Solid Boss created by user_geometry"
                               :browser-image "ugeo_solid_part_brs.xbm"
  )

;; B. register a user defined geometric feature whose tool part is a face part. The tool 
;;    part will be loaded through invoking a function
;;
(defun load-user-defined-solid-boss()
  (let ((res (sd-get-customization-file "ugeo_solid_boss_fp.pkg" 
	       :subdirectory "MoldDesignAdvisor/user_geometry/" 
	       :first-found t)))
    (if res 
        (sd-call-cmds (load_package res))
      nil)
    ))
 
(register-load-plastic-feature "Boss_Face-Part"  
                               :categories "Demo Parts" 
                               :load-tool-func "mold-ui::load-user-defined-solid-boss"
                               :dialog-image "ugeo_solid_boss_fp.xpm"
                               :browser-image "ugeo_face_part_brs.xbm"
  )


;; C. register a user defined geometric feature whose tool part is a model manager part. The tool 
;;    part will be loaded through invoking a function. 
;;    In this example it is assumed that the part stored into Model Manager has the 'elid' "BI69ZHUYXYZUVW".
;;    It is possible to inquire the elid of the current part by calling (oli::SD-DB-ELEMENT-ELID (oli::sd-inq-curr-part))
;;
;(defun load-user-defined-from-db()
;  (if (oli::sd-db-element-exists :database-elid "BI69ZHUYXYZUVW")
;    (sd-call-cmds (oli::sd-db-element-load  :database-elid "BI69ZHUYXYZUVW" :database-type :model))  
;    (display_error "Load Model from Model Manager failed.")
;    ))
; 
;(register-load-plastic-feature "Load_from_Model_Manager"  
;                               :categories "Demo Parts" 
;                               :load-tool-func "mold-ui::load-user-defined-from-db"
;                               :dialog-image "ugeo_solid_boss.xpm"
;                               :browser-image "ugeo_solid_part_brs.xbm"
;  )
