/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct CObjMatList = [ COML_object : SO3_OBJECT, COML_idx : I, COML_bWhole : I, COML_lMaterials : [SO3_MATERIAL r1], COML_lOldMat : [SO3_MATERIAL r1], COML_iCurMat : I, COML_iPrevMat : I ]mkCObjMatList;; struct CMultiMatlist = [ CMM_instance : PInstance, CMM_dlgstr : VUIDlg, CMM_tPos : [F F], CMM_tAlign : [I I], CMM_liststr : VUIList, CMM_lListElem : [VUIListElement r1], CMM_lObjectList : [CObjMatList r1], CMM_lSelectedstr : [CObjMatList r1], CMM_sTitle : S, CMM_sOkButton : S, CMM_sCancelButton : S ]mkCMultiMatlist;; fun applyOldMaterials(objmatstr)= if (objmatstr.COML_bWhole) then ( let sizelist objmatstr.COML_lOldMat -> size in let 0 -> i in while (i < size) do ( let nth_list objmatstr.COML_lOldMat i -> oldmat in SO3EntitySetMaterial objmatstr.COML_object oldmat i; set i = i + 1; ); ) else ( let nth_list objmatstr.COML_lOldMat objmatstr.COML_idx -> oldmat in SO3EntitySetMaterial objmatstr.COML_object oldmat objmatstr.COML_idx; ); set objmatstr.COML_iCurMat = -1; 0;; fun deleteOb(inst, obstr)= let sizelist obstr.CMM_lObjectList -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lObjectList i -> objmatstr in applyOldMaterials objmatstr; set i = i + 1; ); VUIdestroyDialogBox obstr.CMM_dlgstr; 0;; fun cbRevertAll(inst, from, action, param, reply, obstr)= let sizelist obstr.CMM_lObjectList -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lObjectList i -> objmatstr in applyOldMaterials objmatstr; set i = i + 1; ); SendPluginEvent inst "Reverted" param nil; 0;; fun applyListMaterial(objmatstr, matidx)= let nth_list objmatstr.COML_lMaterials matidx -> mat in if (objmatstr.COML_bWhole) then ( let sizelist objmatstr.COML_lOldMat -> size in let 0 -> i in while (i < size) do ( SO3EntitySetMaterial objmatstr.COML_object mat i; set i = i + 1; ); ) else SO3EntitySetMaterial objmatstr.COML_object mat objmatstr.COML_idx; set objmatstr.COML_iCurMat = matidx; 0;; fun cbInterfaceMatSelect(listelem, objmatstr)= let sizelist objmatstr.COML_lMaterials -> size in let 0 -> i in while i < size do ( let nth_list objmatstr.COML_lMaterials i -> mat in if (strcmp listelem.VUILE_sValue (SO3MaterialGetName mat)) != 0 then nil else applyListMaterial objmatstr i; set i = i + 1; ); 0;; fun loadObjectMatlist(obstr, objmatstr)= while obstr.CMM_lListElem != nil do ( VUIremoveListElement (hd obstr.CMM_lListElem); set obstr.CMM_lListElem = tl obstr.CMM_lListElem; ); let sizelist objmatstr.COML_lMaterials -> size in let 0 -> i in while i < size do ( let nth_list objmatstr.COML_lMaterials i -> mat in let VUIaddListElement obstr.CMM_liststr nil SO3MaterialGetName mat nil 1 -> listelem in ( VUIsetListElementCbSelect listelem mkfun2 @cbInterfaceMatSelect objmatstr; set obstr.CMM_lListElem = lcat obstr.CMM_lListElem listelem::nil; ); set i = i + 1; ); 0;; fun cbSelectObj(selectstr, value, obstr)= let sizelist selectstr.VUIS_lValues -> size in let 0 -> i in let hd selectstr.VUIS_lValues -> sValue in ( while (i < size) && (strcmp value sValue) != 0 do ( set i = i + 1; set sValue = nth_list selectstr.VUIS_lValues i; ); loadObjectMatlist obstr (nth_list obstr.CMM_lSelectedstr i); ); 0;; fun getAlign(param)= let [1 1] -> align in let [0.0 0.0] -> pos in let strextr param -> lp in let hd lp -> lp in let 0 -> nb in ( while ((lp != nil) && (nb < 2)) do ( let hd lp -> flag in if (!strcmpi flag "top") then ( mutate align <- [_ 0]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "bottom") then ( mutate align <- [_ 2]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "left") then ( mutate align <- [0 _]; mutate pos <- [10.0 _]; ) else if (!strcmpi flag "right") then ( mutate align <- [2 _]; mutate pos <- [10.0 _]; ) else nil; set lp = tl lp; set nb = nb + 1; ); [pos align]; );; fun getIdList(obstr)= let obstr.CMM_lSelectedstr -> l in let sizelist l -> size in let nil -> selectlist in ( while (size > 0) do ( set size = size - 1; let nth_list l size -> objmatstr in let if objmatstr.COML_bWhole then (loc "OS3DMULTIMATLIST_C0004") else strcat "Id " (itoa objmatstr.COML_idx) -> sId in set selectlist = sId::selectlist; ); selectlist; );; fun cbClickDlg(dlgstr, state, obstr)= if (state == 1) then ( let sizelist obstr.CMM_lSelectedstr -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lSelectedstr i -> objmatstr in set objmatstr.COML_iPrevMat = objmatstr.COML_iCurMat; set i = i + 1; ); ) else ( let sizelist obstr.CMM_lSelectedstr -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lSelectedstr i -> objmatstr in if (objmatstr.COML_iPrevMat < 0) then applyOldMaterials objmatstr else applyListMaterial objmatstr objmatstr.COML_iPrevMat; set i = i + 1; ); ); set obstr.CMM_dlgstr = nil; SendPluginEvent obstr.CMM_instance "Interface closed" nil nil; 0;; fun createSelectionInterface(obstr)= if obstr.CMM_dlgstr == nil then nil else VUIdestroyDialogBox obstr.CMM_dlgstr; let V3DgetSessionView c3dXsession -> viewstr in let if ((strcmp obstr.CMM_sTitle "") == 0) then (loc "OS3DMATLIST_C0001") else obstr.CMM_sTitle -> title in let if ((strcmp obstr.CMM_sOkButton "") == 0) then (loc "OS3DMATLIST_C0002") else obstr.CMM_sOkButton -> okbutton in let if ((strcmp obstr.CMM_sCancelButton "") == 0) then (loc "OS3DMATLIST_C0003") else obstr.CMM_sCancelButton -> cancelbutton in let VUIcreateDialogExt viewstr obstr.CMM_instance.INST_groupstr.GRP_project.PRJ_vuiGroup [350 200] title okbutton cancelbutton 80 (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg obstr) "dialogBox" -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in ( set obstr.CMM_dlgstr = dlgstr; if (sizelist obstr.CMM_lSelectedstr) > 1 then ( let VUIcreateSelect contstr framestr [0.0 0.0] [100.0 30.0] [0 0 1 0 0 0 0 0] [1 0] (getIdList obstr) [5 5] [20 0] -> selectstr in let VUIcreateList contstr framestr [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 (-45)] [1 2] [5 5] 0 [15 5] -> liststr in ( VUIsetSelectCbSelect selectstr mkfun3 @cbSelectObj obstr; set obstr.CMM_liststr = liststr; ); ) else ( let VUIcreateList contstr framestr [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 0] [1 0] [5 5] 0 [15 5] -> liststr in set obstr.CMM_liststr = liststr; ); loadObjectMatlist obstr (hd obstr.CMM_lSelectedstr); VUIsetContainerPos contstr obstr.CMM_tPos obstr.CMM_tAlign nil; VUIshowDialog dlgstr 1; ); 0;; fun cbSelectionInterface(inst, from, action, param, reply, obstr)= if (!strcmp "" (strtrim param)) || param == nil then nil else let getAlign param -> [pos align] in ( set obstr.CMM_tPos = pos; set obstr.CMM_tAlign = align; ); createSelectionInterface obstr; SendPluginEvent inst "Interface opened" nil nil; 0;; fun sortSelected (objmatstr1, objmatstr2)= if objmatstr1.COML_bWhole == 1 then (-1) else if objmatstr2.COML_bWhole == 1 then 1 else objmatstr1.COML_idx - objmatstr2.COML_idx;; fun cbSetObject(inst, from, action, param, reply, obstr)= let strtrim param -> param in let nil -> lselected in if (param == nil) || (strcmp param "") == 0 then nil else ( let sizelist obstr.CMM_lObjectList -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lObjectList i -> objmatstr in let SO3ObjectGetName objmatstr.COML_object -> objname in if (strcmp param objname) != 0 then nil else set lselected = objmatstr::lselected; set i = i + 1; ); if (lselected == nil) then nil else ( set obstr.CMM_lSelectedstr = quicksort lselected @sortSelected; if (obstr.CMM_dlgstr == nil) then nil else ( let sizelist obstr.CMM_lSelectedstr -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CMM_lSelectedstr i -> objmatstr in set objmatstr.COML_iPrevMat = objmatstr.COML_iCurMat; set i = i + 1; ); VUIdestroyDialogBox obstr.CMM_dlgstr; set obstr.CMM_dlgstr = nil; createSelectionInterface obstr; ); ); ); 0;; fun loadObjMatList(inst)= let 0 -> i in let nil -> lobjmat in let getPluginInstanceParam inst (strcat "object_" (itoa i)) -> objname in let atoi (getPluginInstanceParam inst (strcat "idx_" (itoa i))) -> idx in let atoi (getPluginInstanceParam inst (strcat "whole_" (itoa i))) -> whole in ( while (objname != nil) do ( let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3EntityMaterialList obj -> lomat in let (SO3EntityGetResourceGroup obj) -> grpname in let mkCObjMatList[obj idx whole nil lomat (-1) (-1)] -> objmatstr in let 0 -> j in let getPluginInstanceParam inst (strcatn "material_"::(itoa i)::"_"::(itoa j)::nil) -> matname in ( set lobjmat = objmatstr::lobjmat; while (matname != nil) do ( let SO3SceneGetMaterial (V3DgetSession c3dXsession) grpname matname -> mat in set objmatstr.COML_lMaterials = mat::objmatstr.COML_lMaterials; set j = j + 1; set matname = getPluginInstanceParam inst (strcatn "material_"::(itoa i)::"_"::(itoa j)::nil); ); set objmatstr.COML_lMaterials = revertlist objmatstr.COML_lMaterials; ); set i = i + 1; set objname = getPluginInstanceParam inst (strcat "object_" (itoa i)); set idx = atoi (getPluginInstanceParam inst (strcat "idx_" (itoa i))); set whole = atoi (getPluginInstanceParam inst (strcat "whole_" (itoa i))); ); revertlist lobjmat; );; fun newOb(inst)= let loadObjMatList inst -> lobjmat in let getPluginInstanceParam inst "title" -> title in let if title == nil then "" else title -> title in let getPluginInstanceParam inst "okbutton" -> okbutton in let if okbutton == nil then "" else okbutton -> okbutton in let getPluginInstanceParam inst "cancelbutton" -> cancelbutton in let if cancelbutton == nil then "" else cancelbutton -> cancelbutton in let mkCMultiMatlist [inst nil [0.0 0.0] [1 1] nil nil lobjmat nil title okbutton cancelbutton] -> obstr in ( let hd lobjmat -> objmatstr in cbSetObject inst nil nil (SO3ObjectGetName objmatstr.COML_object) nil obstr; PluginRegisterAction inst "Open selection interface" mkfun6 @cbSelectionInterface obstr; PluginRegisterAction inst "Set object" mkfun6 @cbSetObject obstr; PluginRegisterAction inst "Revert all" mkfun6 @cbRevertAll obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;