tree_pane.js 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. //Callback of data preparation stage before UI is fully loaded.
  5. //dcip节点和模型树节点对应值
  6. var g_cur_id2index_cache = {};
  7. var g_cur_index2id_cache = {};
  8. //记录已加载工况
  9. var workcondition = [];
  10. function OnInitializeData(reload, preview) {
  11. PUI(()=>{
  12. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  13. //The 'pui' variable is valid in all functions of this document.
  14. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  15. });
  16. ui.tree_menu.index = 2;
  17. ui.tree_Model.title = ['Part Assemblies/Parts', 'Color', 'UID'];
  18. }
  19. //Callback after UI is fully loaded and displayed.
  20. function OnReady(reload, preview) {
  21. PUI(()=>{
  22. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  23. //The 'pui' variable is valid in all functions of this document.
  24. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  25. });
  26. }
  27. function OnCloseForm() {
  28. }
  29. function OnException(err) {
  30. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  31. }
  32. var options = true;
  33. let myArray = [];
  34. //////////////////////////////////////////////////////////////////////////
  35. // Callback Functions.
  36. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  37. //测试函数
  38. function OnTest(){
  39. //GenerateFile();
  40. // console.log(model.acax_app.path.Name(g_cur_id2index_cache["131"]));
  41. //console.log(g_cur_id2index_cache);
  42. // console.log(g_cur_index2id_cache);
  43. //console.log(model.acax_app.model.materialProp.Current());
  44. //SetUserColor();
  45. let str = unit.form.mainfrm.findRIdById(model.acax_app.model.project.GetModel().pro_model, 100005);
  46. console.log(str);
  47. console.log(comx.occio.GetFacePoint(comx.occore.GetEntryEx(), str));
  48. }
  49. //判断工作流程
  50. function CheckCtrlProcess() {
  51. for(let i = 0 ;i < 6;++i) {
  52. model.global_ctrl[i] = false;
  53. }
  54. //工作区
  55. if(model.acax_app.model.workArea.Current() !== false) {
  56. model.global_ctrl[0] = true;
  57. }else{
  58. return;
  59. }
  60. //工程
  61. if(model.acax_app.model.project.Current() !== "") {
  62. model.global_ctrl[1] = true;
  63. }else{
  64. return;
  65. }
  66. //获取模型存在否
  67. if( model.acax_app.model.project.GetModel().step !== "unimported") {
  68. model.global_ctrl[2] = true;
  69. }else{
  70. return;
  71. }
  72. //工况
  73. if(model.acax_app.model.workCondition.Current() !== "") {
  74. model.global_ctrl[3] = true;
  75. }else{
  76. return;
  77. }
  78. //BBP
  79. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  80. let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
  81. if(model_prop === undefined ) {
  82. model.global_ctrl[4] = false;
  83. }else if(model_prop.BPP){
  84. model.global_ctrl[4] = true;
  85. }
  86. //材料
  87. if(model.acax_app.model.materialProp.Current()) {
  88. model.global_ctrl[5] = true;
  89. }
  90. }
  91. //生成随机颜色
  92. function getRandomHexColor() {
  93. // 随机生成一个 0 到 16777215 之间的整数,并转换为十六进制字符串
  94. let color = Math.floor(Math.random() * 16777216).toString(16);
  95. // 确保颜色代码始终为 6 位
  96. return "#" + color.padStart(6, "0");
  97. }
  98. //生成求解文件
  99. function GenerateFile() {
  100. model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + model.acax_app.model.project.GetModel().step.replace(/\\/g, "/") + " " + model.getCurrentDirectory(), cb => {
  101. console.log(cb);
  102. });
  103. model.acax_app.control.Export(info=>{
  104. //console.log(JSON.stringify(info, null, 2));
  105. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  106. var File = ['结构静力学前处理文件', '\n$ address', info.model3d.step.replace(/\\/g, "/")];
  107. //添加材料
  108. File.push("\n$ materials");
  109. let str = info.mat_prop_list[0]["密度(g/cm^3)"] + " " + info.mat_prop_list[0]["弹性模量(MPa)"] + " " + info.mat_prop_list[0]["泊松比"] + " " +info.mat_prop_list[0]["屈服强度"];
  110. File.push(str);
  111. //添加BPP
  112. File.push("\n$ BPP");
  113. File.push(model.acax_app.view.GetProperty(cut_workcondition_index).BPP.BPP);
  114. //brepFiles
  115. File.push("\n$ brepFiles");
  116. //需要brepFiles文件
  117. let brep_data = model.acax_app.view.GetProperty(cut_workcondition_index).brep;
  118. let brep_arr = Object.keys(brep_data);
  119. for(let i = 0;i < brep_arr.length;++i) {
  120. File.push(brep_data[brep_arr[i]].brep);
  121. }
  122. //forceFace未实现
  123. File.push("\n$ forceFace id xn yn zn xr yr zr");
  124. for(let i = 0;i < info.cons_list.length;++i ) {
  125. if(info.cons_list[i].constraint === "分布载荷压力" && info.cons_list[i]["位置标记"][0] === 'F' ) {
  126. let str0 = info.cons_list[i]["位置标记"].split(" ");
  127. let str1 = str0[2] + " "+ info.cons_list[i]["压力方向fa_x"] + " " + info.cons_list[i]["压力方向fa_y"] + " " + info.cons_list[i]["压力方向fa_z"] + " "+info.cons_list[i]["压力大小fa_xr"] + " " + info.cons_list[i]["压力大小fa_yr"] +" " + info.cons_list[i]["压力大小fa_zr"];
  128. File.push(str1);
  129. }
  130. }
  131. //fixFace未实现
  132. File.push("\n$ fixFace id xn yn zn xr yr zr");
  133. for(let i = 0;i < info.cons_list.length;++i ) {
  134. if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'F' ) {
  135. let str0 = info.cons_list[i].type.split(" ");
  136. let str1 = str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"];
  137. File.push(str1);
  138. }
  139. }
  140. //添加梁和梁节点
  141. for(let i = 0;i < info.cons_list.length;++i ) {
  142. if(info.cons_list[i].constraint === "梁") {
  143. File.push("\n$ mat poi radius len seg Beam");
  144. let str1 = info.cons_list[i]["弹性模量"] + " " + info.cons_list[i]["泊松比"] + " " + info.cons_list[i]["梁约束参数半径"] + " " +info.cons_list[i]["梁约束参数长度"] + " " + info.cons_list[i]["梁约束参数个数"];
  145. File.push(str1);
  146. let len = info.cons_list[i]["梁约束参数个数"];
  147. File.push("\n$ x y z Beam");
  148. for(let j = 0 ; j <= len ;++j){
  149. let str = info.cons_list[i].point[j*3] + " " +info.cons_list[i].point[j*3 +1] + " " +info.cons_list[i].point[j*3 + 2];
  150. File.push(str);
  151. }
  152. }
  153. }
  154. //添加固定支撑
  155. File.push("\n$ con ids id xd yd zd xr yr zr Beam");
  156. for(let i = 0;i < info.cons_list.length;++i ) {
  157. if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') {
  158. let str0 = info.cons_list[i].type.split(" ");
  159. let str1 = str0[1] + " " + str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"];
  160. File.push(str1);
  161. }
  162. }
  163. //添加arrow
  164. File.push("\n$ arrow ids id xn yn zn xr yr zr Beam");
  165. for(let i = 0;i < info.cons_list.length;++i ) {
  166. if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') {
  167. let str0 = info.cons_list[i].type.split(" ");
  168. let str1 = str0[1] + " " + str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"];
  169. File.push(str1);
  170. }
  171. }
  172. //添加弹簧
  173. File.push("\n$ x y z X Y Z stiffness_x stiffness_y stiffness_z type1 type2 Spring");
  174. for(let i = 0;i < info.cons_list.length;++i ) {
  175. if(info.cons_list[i].constraint === "弹簧" && (info.cons_list[i].stypes[0] === 'P' ||info.cons_list[i].stypes[0] === 'B') && (info.cons_list[i].stypee[0] === 'P' ||info.cons_list[i].stypee[0] === 'B')) {
  176. let str1 = info.cons_list[i]["弹簧坐标x"] + " " + info.cons_list[i]["弹簧坐标y"] + " " + info.cons_list[i]["弹簧坐标z"] + " "+info.cons_list[i]["弹簧终点x"] + " " + info.cons_list[i]["弹簧终点y"] +" " + info.cons_list[i]["弹簧终点z"] + " " + info.cons_list[i].stiffness_x +" " + info.cons_list[i].stiffness_y+ " " + info.cons_list[i].stiffness_z + " " + info.cons_list[i].stypes[0] + " " + info.cons_list[i].stypee[0];
  177. File.push(str1);
  178. }
  179. }
  180. //添加连接
  181. File.push("\n$ type id1 id x1 y1 z1 type id1 id x2 y2 z2 xn yn zn xr yr zr Connect");
  182. for(let i = 0;i < info.cons_list.length;++i ) {
  183. if(info.cons_list[i].constraint === "连接" && (info.cons_list[i].ctypes[0] === 'P' ||info.cons_list[i].ctypes[0] === 'B') && (info.cons_list[i].ctpyee[0] === 'P' ||info.cons_list[i].ctpyee[0] === 'B')) {
  184. let str1 = info.cons_list[i].ctypes + " " + info.cons_list[i]["弹簧坐标x"] + " " + info.cons_list[i]["弹簧坐标y"] + " " + info.cons_list[i]["弹簧坐标z"] + " " + info.cons_list[i].ctpyee + " " + info.cons_list[i]["弹簧终点x"] + " " + info.cons_list[i]["弹簧终点y"] +" " + info.cons_list[i]["弹簧终点z"] + " " + info.cons_list[i]["弹簧材料xn"] +" " + info.cons_list[i]["弹簧材料yn"]+ " " + info.cons_list[i]["弹簧材料zn"] + " " + info.cons_list[i]["弹簧材料xr"] + " " + info.cons_list[i]["弹簧材料yr"]+ " "+ info.cons_list[i]["弹簧材料zr"];
  185. File.push(str1);
  186. }
  187. }
  188. //添加rb3
  189. for(let i = 0;i < info.cons_list.length;++i ) {
  190. if(info.cons_list[i].constraint === "rb3") {
  191. File.push("\n$ id RB3");
  192. let str1 = info.cons_list[i]["编号"];
  193. str1 = str1.split(" ");
  194. //console.log(str1);
  195. for(let j = 0;j < str1.length;++j) {
  196. if(str1[j] !== '') {
  197. File.push(str1[j]);
  198. }
  199. }
  200. File.push("\n$ type id ids x y z RB3");
  201. let str = info.cons_list[i].types + " " +info.cons_list[i].x + " " + info.cons_list[i].y + " " + info.cons_list[i].z;
  202. File.push(str);
  203. }
  204. }
  205. //集中载荷rb3
  206. File.push("\n$ arrow type id ids xn yn zn xr yr zr RB3");
  207. for(let i = 0;i < info.cons_list.length;++i ) {
  208. if(info.cons_list[i].constraint === "集中载荷压力" && info.cons_list[i]["位置标记"][0] === 'P' ) {
  209. let str1 = info.cons_list[i]["位置标记"] + " " + info.cons_list[i]["压力方向xn"] + " " + info.cons_list[i]["压力方向yn"] + " "+info.cons_list[i]["压力方向zn"] + " " + info.cons_list[i]["压力大小xr"] +" " + info.cons_list[i]["压力大小yr"]+ " " + info.cons_list[i]["压力大小zr"];
  210. File.push(str1);
  211. }
  212. }
  213. //固定支撑rb3
  214. File.push("\n$ fix type id ids xn yn zn xr yr zr RB3");
  215. for(let i = 0;i < info.cons_list.length;++i ) {
  216. if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'P') {
  217. let str1 = info.cons_list[i].type + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"];
  218. File.push(str1);
  219. }
  220. }
  221. model.writeFile(File);
  222. });
  223. }
  224. function OnTest1(){
  225. console.log(model.acax_app.model.project.GetModel());
  226. //console.log(model.acax_app.model.constrain.Database());
  227. //GenerateFile() ;
  228. //console.log(model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()));
  229. }
  230. //创建约束显示
  231. function CreateContrainShow() {
  232. //console.log(model.acax_app.model.workArea.Current() !== false);
  233. //console.log(model.acax_app.model.project.Current() !== "");
  234. //console.log(model.acax_app.model.workCondition.Current() !== "");
  235. if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){
  236. //获取工况数据库
  237. //console.log(workcondition);
  238. var new_arr_key ;
  239. var constrain_data;
  240. if(model.acax_app.model.workCondition.Current() === "") {
  241. new_arr_key = [];
  242. }else{
  243. constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
  244. if(Object.keys(constrain_data.constrain.db).length !== 0) {
  245. new_arr_key = Object.keys(constrain_data.constrain.db);
  246. }else{
  247. new_arr_key = [];
  248. }
  249. }
  250. //查看当前工程工况是否已加载
  251. const path1 = model.acax_app.model.workArea.Current();
  252. const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1);
  253. var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current();
  254. var flag = 1;
  255. console.log(workcondition.includes(cur_name));
  256. if(workcondition.includes(cur_name)) {
  257. for(let i = 0;i < new_arr_key.length;++i) {
  258. let type = constrain_data.constrain.db[new_arr_key[i]].cons_type;
  259. unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[new_arr_key[i]].unique, false);
  260. if(type === "rb3" && flag) {
  261. unit.form.mainfrm.HideAndShow("pick", "rb3", false);
  262. flag = 0;
  263. }
  264. }
  265. ShowPoints();
  266. ShowMarks();
  267. }else{
  268. for(let i = 0;i < new_arr_key.length;++i) {
  269. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "集中载荷压力") {
  270. unit.form.mainfrm.OnArrows(constrain_data.constrain.db[new_arr_key[i]]["位置坐标x"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标y"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标z"], constrain_data.constrain.db[new_arr_key[i]]["压力方向xn"], constrain_data.constrain.db[new_arr_key[i]]["压力方向yn"], constrain_data.constrain.db[new_arr_key[i]]["压力方向zn"], constrain_data.constrain.db[new_arr_key[i]].unique);
  271. }
  272. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "固定支撑") {
  273. unit.form.mainfrm.OnConstrains(constrain_data.constrain.db[new_arr_key[i]].xc, constrain_data.constrain.db[new_arr_key[i]].yc, constrain_data.constrain.db[new_arr_key[i]].zc, constrain_data.constrain.db[new_arr_key[i]].unique);
  274. }
  275. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "梁") {
  276. unit.form.mainfrm.OnBeams(constrain_data.constrain.db[new_arr_key[i]]["梁约束参数个数"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置xDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置yDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置zDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置xCoord"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置yCoord"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置zCoord"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]]["梁节点大小半径"], constrain_data.constrain.db[new_arr_key[i]].unique);
  277. }
  278. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "连接") {
  279. unit.form.mainfrm.OnConnects(constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标z"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点z"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]].unique);
  280. }
  281. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "弹簧") {
  282. unit.form.mainfrm.OnSpring(constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标z"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点z"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]].unique);
  283. }
  284. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "分布载荷压力") {
  285. unit.form.mainfrm.OnArrows(constrain_data.constrain.db[new_arr_key[i]]["位置坐标x"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标y"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标z"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_x"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_y"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_z"], constrain_data.constrain.db[new_arr_key[i]].unique);
  286. }
  287. if(constrain_data.constrain.db[new_arr_key[i]].constraint === "rb3") {
  288. unit.form.mainfrm.OnGenerateGuass(constrain_data.constrain.db[new_arr_key[i]]["编号"]);
  289. unit.form.mainfrm.OnSpheres(constrain_data.constrain.db[new_arr_key[i]].x, constrain_data.constrain.db[new_arr_key[i]].y, constrain_data.constrain.db[new_arr_key[i]].z, constrain_data.constrain.db[new_arr_key[i]].radius, constrain_data.constrain.db[new_arr_key[i]].unique);
  290. }
  291. }
  292. //加载点
  293. OnLoadPoints();
  294. OnLoadMarks();
  295. workcondition.push(cur_name);
  296. }
  297. }
  298. }
  299. //已创建但被隐藏,显示点
  300. function ShowPoints() {
  301. console.log("1111");
  302. let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
  303. let point_model = model.acax_app.view.GetProperty(work_condition).point;
  304. let point_arr = Object.keys(point_model);
  305. for(let i = 0;i < point_arr.length;++i) {
  306. unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, false);
  307. }
  308. }
  309. //已创建但被隐藏,显示Mark
  310. function ShowMarks() {
  311. let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
  312. let mark_model = model.acax_app.view.GetProperty(work_condition).mark;
  313. let mark_arr = Object.keys(mark_model);
  314. for(let i = 0;i < mark_arr.length;++i) {
  315. unit.form.mainfrm.HideAndShow("mark", mark_model[mark_arr[i]].name, false);
  316. }
  317. }
  318. //加载点
  319. function OnLoadPoints() {
  320. let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
  321. if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).point !== undefined ) {
  322. let point_model = model.acax_app.view.GetProperty(work_condition).point;
  323. let point_arr = Object.keys(point_model);
  324. for(let i = 0;i < point_arr.length;++i) {
  325. unit.form.mainfrm.OnSetPoints(point_model[point_arr[i]].x, point_model[point_arr[i]].y, point_model[point_arr[i]].z, point_model[point_arr[i]].radius, point_model[point_arr[i]].name);
  326. }
  327. }
  328. }
  329. //加载Mark
  330. function OnLoadMarks() {
  331. let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
  332. if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).mark !== undefined ) {
  333. let mark_model = model.acax_app.view.GetProperty(work_condition).mark;
  334. let mark_arr = Object.keys(mark_model);
  335. for(let i = 0;i < mark_arr.length;++i) {
  336. unit.form.mainfrm.OnSetMarks(mark_model[mark_arr[i]].x, mark_model[mark_arr[i]].y, mark_model[mark_arr[i]].z, mark_model[mark_arr[i]].R, mark_model[mark_arr[i]].G, mark_model[mark_arr[i]].B, mark_model[mark_arr[i]]["字体大小"], mark_model[mark_arr[i]]["标记命名"], mark_model[mark_arr[i]].name);
  337. }
  338. }
  339. }
  340. //隐藏旧的工况
  341. function HideWorkcondition() {
  342. if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){
  343. let old_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  344. var point_model;
  345. var point_arr;
  346. if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).point === undefined) {
  347. point_model = {};
  348. }else{
  349. point_model = model.acax_app.view.GetProperty(old_workcondition_index).point;
  350. }
  351. point_arr = Object.keys(point_model);
  352. var mark_model;
  353. var mark_arr;
  354. if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).mark === undefined) {
  355. mark_model = {};
  356. }else{
  357. mark_model = model.acax_app.view.GetProperty(old_workcondition_index).mark;
  358. }
  359. mark_arr = Object.keys(mark_model);
  360. let constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
  361. var old_arr_key ;
  362. if(Object.keys(constrain_data.constrain.db).length !== 0) {
  363. old_arr_key = Object.keys(constrain_data.constrain.db);
  364. }else{
  365. old_arr_key = [];
  366. }
  367. //查看当前工程工况是否已加载
  368. const path1 = model.acax_app.model.workArea.Current();
  369. const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1);
  370. var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current();
  371. var flag = 1;
  372. if(workcondition.includes(cur_name)) {
  373. for(let i = 0;i <old_arr_key.length;++i ) {
  374. let type = constrain_data.constrain.db[old_arr_key[i]].cons_type;
  375. unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[old_arr_key[i]].unique, true);
  376. if(type === "rb3" && flag) {
  377. unit.form.mainfrm.HideAndShow("pick", "rb3", true);
  378. flag = 0;
  379. }
  380. }
  381. for(let i = 0;i < point_arr.length;++i) {
  382. unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, true);
  383. }
  384. for(let i = 0;i < mark_arr.length;++i) {
  385. unit.form.mainfrm.HideAndShow("mark", mark_model[mark_arr[i]].name, true);
  386. }
  387. }
  388. }
  389. }
  390. //获取当前工作区名称加当前工程名称加当前工况名称
  391. function GetCurUniqueName() {
  392. const path = model.acax_app.model.workArea.Database().list[0];
  393. const workarea_name =path.substring(path.lastIndexOf('/') + 1);
  394. const proj_name = model.acax_app.model.project.Current();
  395. const workcondition_name = model.acax_app.model.workCondition.Current();
  396. return workarea_name + proj_name + workcondition_name;
  397. }
  398. //生成Mark
  399. function SetMark(markss) {
  400. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  401. let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
  402. //console.log(model_prop);
  403. if(model_prop === undefined ) {
  404. model_prop = {};
  405. let mark = {};
  406. mark.mark1 = markss;
  407. model_prop.mark = mark;
  408. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  409. }else if(model_prop.mark === undefined){
  410. let mark = {};
  411. mark.mark1 = markss;
  412. model_prop.mark = mark;
  413. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  414. }else{
  415. let len = Object.keys(model_prop.mark).length;
  416. let temp = "mark" + (len + 1);
  417. model_prop.mark[temp] = markss;
  418. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  419. }
  420. //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
  421. }
  422. //生成点
  423. function SetPoint(node) {
  424. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  425. let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
  426. if(model_prop === undefined ) {
  427. model_prop = {};
  428. let point = {};
  429. point.point1 = node;
  430. //console.log(point);
  431. model_prop.point = point;
  432. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  433. }else if(model_prop.point === undefined){
  434. let point = {};
  435. point.point1 = node;
  436. //console.log(point);
  437. model_prop.point = point;
  438. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  439. }else{
  440. let len = Object.keys(model_prop.point).length;
  441. let temp = "point" + (len + 1);
  442. model_prop.point[temp] = node;
  443. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  444. }
  445. //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
  446. }
  447. //生成brep文件
  448. function SetBrepFile(brep_path){
  449. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  450. let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
  451. if(model_prop === undefined ) {
  452. model_prop = {};
  453. let brep = {};
  454. brep.brep1 = brep_path;
  455. //console.log(brep);
  456. model_prop.brep = brep;
  457. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  458. }else if(model_prop.brep === undefined){
  459. let brep = {};
  460. brep.brep1 = brep_path;
  461. model_prop.brep = brep;
  462. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  463. }else{
  464. let brep_arr = Object.keys(model_prop.brep);
  465. var i = 0;
  466. for( i = 0;i < brep_arr.length;++i) {
  467. if(model_prop.brep[brep_arr[i]].brep === brep_path.brep) {
  468. break;
  469. }
  470. }
  471. if(i === brep_arr.length) {
  472. let temp = "brep" + (brep_arr.length + 1);
  473. model_prop.brep[temp] = brep_path;
  474. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  475. }
  476. }
  477. //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
  478. }
  479. //生成BPP
  480. function SetBPPProperty(BPP) {
  481. let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  482. let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
  483. if(model_prop === undefined) {
  484. model_prop = {};
  485. model_prop.BPP = BPP;
  486. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  487. }else{
  488. model_prop.BPP = BPP;
  489. model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
  490. }
  491. model.global_ctrl[4] = true;
  492. }
  493. //修改约束属性的名字
  494. function ModifyConstraintName(new_name) {
  495. let tree_color = [];
  496. let cur_name = model.acax_app.model.constrain.Current();
  497. let flag = model.acax_app.control.constrain.Rename(cur_name, new_name);
  498. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  499. let cur_id;
  500. if(flag === false) {
  501. unit.form.mainfrm.OnCueline('修改失败', 'red');
  502. }else{
  503. unit.form.mainfrm.OnCueline('修改成功', 'green');
  504. }
  505. model.acax_app.view.RenderTree(() => {
  506. g_cur_id2index_cache = {};
  507. g_cur_index2id_cache = {};
  508. }, info=>{
  509. let icon = "";
  510. let color = "";
  511. //设置id
  512. let cur_check_state = 0;
  513. let cur_type = model.acax_app.path.Type(info.index);
  514. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  515. cur_check_state = 3;
  516. }
  517. let id2index = g_cur_id2index_cache;
  518. let index2id = g_cur_index2id_cache;
  519. let index = info.index;
  520. let id = info.id;
  521. //赋予图标
  522. if(CheckPicture(cur_type)){
  523. icon = CheckPicture(cur_type);
  524. }
  525. if(index) {
  526. id2index[id] = index;
  527. index2id[index] = id;
  528. }
  529. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  530. cur_id = info.id;
  531. }
  532. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  533. color = "#bbbbbb";
  534. }
  535. //获取约束颜色
  536. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  537. color = model.acax_app.model.constrain.Get(info.name).color;
  538. }
  539. //将第一个节点设为无选择框
  540. if(info.id === 1) {
  541. cur_check_state = 3;
  542. icon = "form";
  543. }
  544. return {
  545. name : info.name,
  546. icon : icon,
  547. id : info.id,
  548. check_state : cur_check_state,
  549. color : color
  550. };
  551. },
  552. tree => {
  553. //从工程中获取保存的model数据
  554. if(model.acax_app.model.project.GetModel().pro_model){
  555. //获取当前工程的名字
  556. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  557. let pro_name = model.acax_app.path.Name(pro_Index);
  558. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  559. findAndAppendByName(tree, pro_name, cur_model);
  560. }
  561. //赋值给dcip的树结构
  562. tree_color = getTreeColorsInOrder(tree);
  563. ui.tree_Model.tree = tree;
  564. }
  565. );
  566. //渲染3d模型
  567. if(model.acax_app.model.project.GetModel().step === "unimported") {
  568. unit.form.mainfrm.ClearCanvas();
  569. }else{
  570. model.acax_app.view.Render3D(info=>{
  571. unit.form.mainfrm.OnloadModel(info.model3d.step);
  572. });
  573. }
  574. ui.tree_Model.column = [1, tree_color];
  575. ui.tree_Model.position = cur_id;
  576. }
  577. //修改材料属性的名字
  578. function ModifyMaterialName(new_name) {
  579. let tree_color = [];
  580. let cur_name = model.acax_app.model.materialProp.Current();
  581. let flag = model.acax_app.control.materialProp.Rename(cur_name, new_name);
  582. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  583. let cur_id;
  584. if(flag === true) {
  585. unit.form.mainfrm.OnCueline('修改成功', 'green');
  586. }else{
  587. unit.form.mainfrm.OnCueline('修改失败', 'red');
  588. }
  589. model.acax_app.view.RenderTree(() => {
  590. g_cur_id2index_cache = {};
  591. g_cur_index2id_cache = {};
  592. }, info=>{
  593. let icon = "";
  594. let color = "";
  595. //设置id
  596. let cur_check_state = 0;
  597. let cur_type = model.acax_app.path.Type(info.index);
  598. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  599. cur_check_state = 3;
  600. }
  601. let id2index = g_cur_id2index_cache;
  602. let index2id = g_cur_index2id_cache;
  603. let index = info.index;
  604. let id = info.id;
  605. //赋予图标
  606. if(CheckPicture(cur_type)){
  607. icon = CheckPicture(cur_type);
  608. }
  609. if(index) {
  610. id2index[id] = index;
  611. index2id[index] = id;
  612. }
  613. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  614. cur_id = info.id;
  615. }
  616. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  617. color = "#bbbbbb";
  618. }
  619. //获取约束颜色
  620. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  621. color = model.acax_app.model.constrain.Get(info.name).color;
  622. }
  623. //将第一个节点设为无选择框
  624. if(info.id === 1) {
  625. cur_check_state = 3;
  626. icon = "form";
  627. }
  628. return {
  629. name : info.name,
  630. icon : icon,
  631. id : info.id,
  632. check_state : cur_check_state,
  633. color : color
  634. };
  635. },
  636. tree => {
  637. //从工程中获取保存的model数据
  638. if(model.acax_app.model.project.GetModel().pro_model){
  639. //获取当前工程的名字
  640. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  641. let pro_name = model.acax_app.path.Name(pro_Index);
  642. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  643. findAndAppendByName(tree, pro_name, cur_model);
  644. }
  645. //赋值给dcip的树结构
  646. tree_color = getTreeColorsInOrder(tree);
  647. ui.tree_Model.tree = tree;
  648. }
  649. );
  650. //渲染3d模型
  651. if(model.acax_app.model.project.GetModel().step === "unimported") {
  652. unit.form.mainfrm.ClearCanvas();
  653. }else{
  654. model.acax_app.view.Render3D(info=>{
  655. unit.form.mainfrm.OnloadModel(info.model3d.step);
  656. });
  657. }
  658. ui.tree_Model.column = [1, tree_color];
  659. ui.tree_Model.position = cur_id;
  660. }
  661. //修改的工程名
  662. function ModifyProName(new_name) {
  663. let tree_color = [];
  664. let cur_name = model.acax_app.path.Name(model.acax_app.view.GetCurrentProjectIndex());
  665. model.acax_app.model.project.Rename(cur_name, new_name);
  666. let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
  667. let cur_id;
  668. model.acax_app.view.RenderTree(() => {
  669. g_cur_id2index_cache = {};
  670. g_cur_index2id_cache = {};
  671. }, info=>{
  672. let icon = "";
  673. let color = "";
  674. //设置id
  675. let cur_check_state = 0;
  676. let cur_type = model.acax_app.path.Type(info.index);
  677. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  678. cur_check_state = 3;
  679. }
  680. let id2index = g_cur_id2index_cache;
  681. let index2id = g_cur_index2id_cache;
  682. let index = info.index;
  683. let id = info.id;
  684. //赋予图标
  685. if(CheckPicture(cur_type)){
  686. icon = CheckPicture(cur_type);
  687. }
  688. if(index) {
  689. id2index[id] = index;
  690. index2id[index] = id;
  691. }
  692. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
  693. cur_id = info.id;
  694. }
  695. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  696. color = "#bbbbbb";
  697. }
  698. //获取约束颜色
  699. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  700. color = model.acax_app.model.constrain.Get(info.name).color;
  701. }
  702. //将第一个节点设为无选择框
  703. if(info.id === 1) {
  704. cur_check_state = 3;
  705. icon = "form";
  706. }
  707. return {
  708. name : info.name,
  709. icon : icon,
  710. id : info.id,
  711. check_state : cur_check_state,
  712. color : color
  713. };
  714. },
  715. tree => {
  716. //从工程中获取保存的model数据
  717. if(model.acax_app.model.project.GetModel().pro_model){
  718. //获取当前工程的名字
  719. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  720. let pro_name = model.acax_app.path.Name(pro_Index);
  721. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  722. findAndAppendByName(tree, pro_name, cur_model);
  723. }
  724. //赋值给dcip的树结构
  725. tree_color = getTreeColorsInOrder(tree);
  726. ui.tree_Model.tree = tree;
  727. }
  728. );
  729. //渲染3d模型
  730. if(model.acax_app.model.project.GetModel().step === "unimported") {
  731. unit.form.mainfrm.ClearCanvas();
  732. }else{
  733. model.acax_app.view.Render3D(info=>{
  734. unit.form.mainfrm.OnloadModel(info.model3d.step);
  735. });
  736. }
  737. ui.tree_Model.column = [1, tree_color];
  738. ui.tree_Model.position = cur_id;
  739. }
  740. //处理字符串截掉后五位
  741. function removeLastFiveCharacters(str) {
  742. str = String(str);
  743. if (str.length <= 5) {
  744. return ''; // 如果字符串长度小于等于 5,则返回空字符串
  745. }
  746. return str.substring(0, str.length - 5); // 提取从 0 到倒数第 5 位的子字符串
  747. }
  748. //点击弹出菜单
  749. function OnContentClick(){
  750. //获取一级子节点
  751. let str = removeLastFiveCharacters(ui.tree_Model.content_menu);
  752. let model_id = g_cur_id2index_cache[str];
  753. //let cur_name = model.acax_app.path.Name(model_id);
  754. switch (model.acax_app.path.Type(model_id)){
  755. case 2:
  756. //unit.form.Rename.Show();
  757. break;
  758. case 3:
  759. break;
  760. case 4:
  761. unit.form.RenameConstraint.Show();
  762. break;
  763. case 5:
  764. unit.form.RenameMaterial.Show();
  765. break;
  766. default:
  767. break;
  768. }
  769. }
  770. //右键单击树效果
  771. function OnRightClick(){
  772. let model_id = g_cur_id2index_cache[ui.tree_Model.position];
  773. switch (model.acax_app.path.Type(model_id)){
  774. case 2:
  775. /*ui.tree_Model.content_menu =[{
  776. "name":"重命名",
  777. "icon":"",
  778. "id":ui.tree_Model.position + "13579"
  779. }];*/
  780. break;
  781. case 3:
  782. break;
  783. case 4:
  784. ui.tree_Model.content_menu =[{
  785. "name":"重命名",
  786. "icon":"",
  787. "id":ui.tree_Model.position + "13579"
  788. }];
  789. break;
  790. case 5:
  791. ui.tree_Model.content_menu =[{
  792. "name":"重命名",
  793. "icon":"",
  794. "id":ui.tree_Model.position + "13579"
  795. }];
  796. break;
  797. default:
  798. break;
  799. }
  800. }
  801. //点击树
  802. function OnClickTree(id, column, text){
  803. //获取模型树的对应节点
  804. let model_id = g_cur_id2index_cache[ui.tree_Model.position];
  805. let cur_workarea = model.acax_app.view.GetCurrentWorkAreaIndex();
  806. let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
  807. let cur_workcondition = model.acax_app.view.GetCurrentWorkConditionIndex();
  808. model.acax_app.view.RenderNode(model_id, info => {
  809. console.log(info);
  810. });
  811. switch (model.acax_app.path.Type(model_id)) {
  812. //切换工作区
  813. case 0:
  814. //不是当前工作区,切换工作区
  815. if(model_id !== cur_workarea){
  816. model.acax_app.view.RenderNode(model_id, info => {
  817. //隐藏工作区工况
  818. HideWorkcondition();
  819. OpenWorkArea(info.prop);
  820. //切换到当前工作区
  821. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  822. });
  823. }
  824. break;
  825. //选中材料库
  826. case 1:
  827. break;
  828. //切换工程
  829. case 2:
  830. //不是当前工程,切换工程
  831. if(model_id !== cur_proj){
  832. //隐藏掉旧的工况
  833. HideWorkcondition();
  834. model.acax_app.view.RenderNode(model_id, info => {
  835. //切换工程
  836. ChangePro(model.acax_app.path.Name(model_id));
  837. //切换到当前工程
  838. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  839. //在canvas显示新的约束
  840. CreateContrainShow();
  841. });
  842. }
  843. break;
  844. //切换工况
  845. case 3:
  846. //不是当前工况,切换工况
  847. if(model_id !== cur_workcondition){
  848. model.acax_app.view.RenderNode(model_id, info => {
  849. //隐藏工况
  850. HideWorkcondition();
  851. //切换工况,旧的隐藏
  852. let old_data = ChangeWorkCondition(model.acax_app.path.Name(model_id));
  853. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  854. //显示工况
  855. CreateContrainShow();
  856. });
  857. }
  858. break;
  859. //选中约束
  860. case 4:
  861. model.acax_app.view.RenderNode(model_id, info => {
  862. //切换到当前约束
  863. model.acax_app.model.constrain.SwitchTo(model.acax_app.path.Name(model_id));
  864. //将约束属性设置到对应面板
  865. ChangeConstraint(Object.values(info.prop)[0], info.prop);
  866. //切换点击约束
  867. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  868. //渲染到3D模型
  869. if(ui.tree_Model.node.check_state === 2) {
  870. unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, false);
  871. console.log("show");
  872. }else if(ui.tree_Model.node.check_state === 0) {
  873. unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, true);
  874. console.log("hide");
  875. }
  876. });
  877. break;
  878. //选中材料属性
  879. case 5:
  880. model.acax_app.view.RenderNode(model_id, info => {
  881. //切换当前材料
  882. model.acax_app.model.materialProp.SwitchTo(model.acax_app.path.Name(model_id));
  883. unit.form.mainfrm.menu(3);
  884. unit.form.mainfrm.OnChangePicture(2, 1);
  885. unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
  886. //将材料属性设置到面板
  887. unit.form.mainfrm.setMaterial(info.prop);
  888. //切换到点击材料
  889. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  890. });
  891. break;
  892. default:
  893. break;
  894. }
  895. if(column === 1) {
  896. var clr = ui.ColorDialog(text);
  897. let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
  898. let temp = model.acax_app.view.GetProperty(cut_project_index);
  899. temp.color[id] = clr;
  900. model.acax_app.view.SetProperty(cut_project_index, temp);
  901. let rgb = hexToRgb(clr);
  902. unit.form.mainfrm.LightFace(id, rgb);
  903. if(clr) {
  904. ui.tree_Model.column = [column, clr];
  905. }
  906. }
  907. }
  908. //16进制转rgb
  909. function hexToRgb(hex) {
  910. // 去掉前缀 #(如果有)
  911. hex = hex.replace(/^#/, '');
  912. // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB)
  913. if (hex.length === 3) {
  914. hex = hex.split('').map(char => char + char).join('');
  915. }
  916. // 解析 RGB 颜色值
  917. const r = parseInt(hex.slice(0, 2), 16);
  918. const g = parseInt(hex.slice(2, 4), 16);
  919. const b = parseInt(hex.slice(4, 6), 16);
  920. return { r, g, b };
  921. }
  922. //切换约束面板
  923. function ChangeConstraint(constraint_name, prop) {
  924. let constraint = {
  925. "固定支撑":function(){
  926. unit.form.mainfrm.OnChangeIndex(2);
  927. unit.form.mainfrm.menu(18);
  928. unit.form.mainfrm.changeConstrain(1, 0);
  929. // unit.form.mainfrm.OnChange
  930. unit.form.mainfrm.OnConChange(0);
  931. unit.form.mainfrm.setConstraint(prop);
  932. },
  933. "梁":function(){
  934. unit.form.mainfrm.OnChangeIndex(2);
  935. unit.form.mainfrm.menu(18);
  936. unit.form.mainfrm.changeConstrain(1, 1);
  937. unit.form.mainfrm.changeConstrain(2, 0);
  938. unit.form.mainfrm.OnConChange(1);
  939. unit.form.mainfrm.setConstraint(prop);
  940. },
  941. "弹簧":function(){
  942. unit.form.mainfrm.OnChangeIndex(2);
  943. unit.form.mainfrm.menu(18);
  944. unit.form.mainfrm.changeConstrain(1, 1);
  945. unit.form.mainfrm.changeConstrain(2, 1);
  946. unit.form.mainfrm.OnConChange(1);
  947. unit.form.mainfrm.setConstraint(prop);
  948. },
  949. "连接":function(){
  950. unit.form.mainfrm.OnChangeIndex(2);
  951. unit.form.mainfrm.menu(18);
  952. unit.form.mainfrm.changeConstrain(1, 1);
  953. unit.form.mainfrm.changeConstrain(2, 2);
  954. unit.form.mainfrm.OnConChange(1);
  955. unit.form.mainfrm.setConstraint(prop);
  956. },
  957. "梁(非均匀)":function(){
  958. },
  959. "集中载荷压力":function(){
  960. unit.form.mainfrm.OnChangeIndex(2);
  961. unit.form.mainfrm.menu(17);
  962. unit.form.mainfrm.changeConstrain(3, 0);
  963. unit.form.mainfrm.OnForceChange(0);
  964. unit.form.mainfrm.setConstraint(prop);
  965. },
  966. "分布载荷压力":function(){
  967. unit.form.mainfrm.OnChangeIndex(2);
  968. unit.form.mainfrm.menu(17);
  969. unit.form.mainfrm.changeConstrain(3, 1);
  970. unit.form.mainfrm.OnForceChange(1);
  971. unit.form.mainfrm.setConstraint(prop);
  972. },
  973. "rb3":function(){
  974. unit.form.mainfrm.OnChangeIndex(2);
  975. unit.form.mainfrm.menu(23);
  976. unit.form.mainfrm.setConstraint(prop);
  977. }
  978. };
  979. constraint[constraint_name]();
  980. }
  981. //判断图标
  982. function CheckPicture(idx) {
  983. switch (idx) {
  984. case 0:
  985. return "workarea";
  986. case 2:
  987. return "project";
  988. case 3:
  989. return "workcondition";
  990. case 4:
  991. return "constrain";
  992. case 5:
  993. return "materialproperty";
  994. default:
  995. return null; // 或者抛出一个错误,比如 `throw new Error("Invalid index");`
  996. }
  997. }
  998. //切换工作区
  999. function OpenWorkArea(fname) {
  1000. let tree_color = [];
  1001. fname = fname.replace(/\/+/g, "\\");
  1002. var work_path = model.acax_app.model.workArea.List();
  1003. //渲染模型树
  1004. for(var i = 0;i < work_path.length;++i) {
  1005. work_path[i] = work_path[i].replace(/\/+/g, "\\");
  1006. if(fname === work_path[i]){
  1007. model.acax_app.control.workArea.SwitchTo(i);
  1008. //渲染3d模型
  1009. if(model.acax_app.model.project.GetModel().step === "unimported") {
  1010. unit.form.mainfrm.ClearCanvas();
  1011. model.acax_app.view.RenderTree(() => {
  1012. g_cur_id2index_cache = {};
  1013. g_cur_index2id_cache = {};
  1014. }, info=>{
  1015. let icon = "";
  1016. let color = "";
  1017. //设置id
  1018. let cur_check_state = 0;
  1019. let cur_type = model.acax_app.path.Type(info.index);
  1020. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1021. cur_check_state = 3;
  1022. }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1023. cur_check_state = 2;
  1024. }
  1025. //赋予图标
  1026. if(CheckPicture(cur_type)){
  1027. icon = CheckPicture(cur_type);
  1028. }
  1029. let id2index = g_cur_id2index_cache;
  1030. let index2id = g_cur_index2id_cache;
  1031. let index = info.index;
  1032. let id = info.id;
  1033. if(index) {
  1034. id2index[id] = index;
  1035. index2id[index] = id;
  1036. }
  1037. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1038. color = "#bbbbbb";
  1039. }
  1040. //获取约束颜色
  1041. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1042. color = model.acax_app.model.constrain.Get(info.name).color;
  1043. }
  1044. //将第一个节点设为无选择框
  1045. if(info.id === 1) {
  1046. cur_check_state = 3;
  1047. icon = "form";
  1048. }
  1049. return {
  1050. name : info.name,
  1051. icon : icon,
  1052. id : info.id,
  1053. check_state : cur_check_state,
  1054. color : color
  1055. };
  1056. },
  1057. tree => {
  1058. //赋值给dcip的树结构
  1059. tree_color = getTreeColorsInOrder(tree);
  1060. ui.tree_Model.tree = tree;
  1061. ui.tree_Model.column = [1, tree_color];
  1062. }
  1063. );
  1064. }else{
  1065. model.acax_app.view.Render3D(info=>{
  1066. unit.form.mainfrm.OnloadModel(info.model3d.step);
  1067. unit.form.mainfrm.SetColor(difference);
  1068. CreateContrainShow();
  1069. });
  1070. }
  1071. }
  1072. }
  1073. CheckCtrlProcess();
  1074. console.log(model.global_ctrl);
  1075. }
  1076. //切换工程
  1077. function ChangePro(pro_name) {
  1078. let tree_color = [];
  1079. model.acax_app.control.project.SwitchTo(pro_name);
  1080. //渲染3d模型
  1081. if(model.acax_app.model.project.GetModel().step === "unimported") {
  1082. unit.form.mainfrm.ClearCanvas();
  1083. model.acax_app.view.RenderTree(() => {
  1084. g_cur_id2index_cache = {};
  1085. g_cur_index2id_cache = {};
  1086. }, info=>{
  1087. let icon = "";
  1088. let color = "";
  1089. //设置id
  1090. let cur_check_state = 0;
  1091. let cur_type = model.acax_app.path.Type(info.index);
  1092. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1093. cur_check_state = 3;
  1094. }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1095. cur_check_state = 2;
  1096. }
  1097. let id2index = g_cur_id2index_cache;
  1098. let index2id = g_cur_index2id_cache;
  1099. let index = info.index;
  1100. let id = info.id;
  1101. //赋予图标
  1102. if(CheckPicture(cur_type)){
  1103. icon = CheckPicture(cur_type);
  1104. }
  1105. if(index) {
  1106. id2index[id] = index;
  1107. index2id[index] = id;
  1108. }
  1109. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1110. color = "#bbbbbb";
  1111. }
  1112. //将第一个节点设为无选择框
  1113. if(info.id === 1) {
  1114. cur_check_state = 3;
  1115. icon = "form";
  1116. }
  1117. //获取约束颜色
  1118. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1119. color = model.acax_app.model.constrain.Get(info.name).color;
  1120. }
  1121. return {
  1122. name : info.name,
  1123. icon : icon,
  1124. id : info.id,
  1125. check_state : cur_check_state,
  1126. color : color
  1127. };
  1128. },
  1129. tree => {
  1130. //从工程中获取保存的model数据
  1131. //console.log(model.acax_app.model.project.GetModel().pro_model);
  1132. if(model.acax_app.model.project.GetModel().pro_model){
  1133. //获取当前工程的名字
  1134. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  1135. let pro_name = model.acax_app.path.Name(pro_Index);
  1136. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  1137. findAndAppendByName(tree, pro_name, cur_model);
  1138. }
  1139. //赋值给dcip的树结构
  1140. tree_color = getTreeColorsInOrder(tree);
  1141. ui.tree_Model.tree = tree;
  1142. ui.tree_Model.column = [1, tree_color];
  1143. }
  1144. );
  1145. }else{
  1146. model.acax_app.view.Render3D(info=>{
  1147. unit.form.mainfrm.OnloadModel(info.model3d.step);
  1148. unit.form.mainfrm.SetColor(difference);
  1149. });
  1150. }
  1151. CheckCtrlProcess();
  1152. console.log(model.global_ctrl);
  1153. }
  1154. //切换工况
  1155. function ChangeWorkCondition(wor_name) {
  1156. let tree_color = [];
  1157. var old_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
  1158. model.acax_app.control.workCondition.SwitchTo(wor_name);
  1159. model.acax_app.view.RenderTree(() => {
  1160. g_cur_id2index_cache = {};
  1161. g_cur_index2id_cache = {};
  1162. }, info=>{
  1163. let icon = "";
  1164. let color = "";
  1165. //设置id
  1166. let cur_check_state = 0;
  1167. let cur_type = model.acax_app.path.Type(info.index);
  1168. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1169. cur_check_state = 3;
  1170. }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1171. cur_check_state = 2;
  1172. }
  1173. let id2index = g_cur_id2index_cache;
  1174. let index2id = g_cur_index2id_cache;
  1175. let index = info.index;
  1176. let id = info.id;
  1177. //赋予图标
  1178. if(CheckPicture(cur_type)){
  1179. icon = CheckPicture(cur_type);
  1180. }
  1181. if(index) {
  1182. id2index[id] = index;
  1183. index2id[index] = id;
  1184. }
  1185. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1186. color = "#bbbbbb";
  1187. }
  1188. //获取约束颜色
  1189. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1190. color = model.acax_app.model.constrain.Get(info.name).color;
  1191. }
  1192. //将第一个节点设为无选择框
  1193. if(info.id === 1) {
  1194. cur_check_state = 3;
  1195. icon = "form";
  1196. }
  1197. return {
  1198. name : info.name,
  1199. icon : icon,
  1200. id : info.id,
  1201. check_state : cur_check_state,
  1202. color : color
  1203. };
  1204. },
  1205. tree => {
  1206. //从工程中获取保存的model数据
  1207. if(model.acax_app.model.project.GetModel().pro_model){
  1208. //获取当前工程的名字
  1209. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  1210. let pro_name = model.acax_app.path.Name(pro_Index);
  1211. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  1212. findAndAppendByName(tree, pro_name, cur_model);
  1213. }
  1214. //赋值给dcip的树结构
  1215. tree_color = getTreeColorsInOrder(tree);
  1216. ui.tree_Model.tree = tree;
  1217. }
  1218. );
  1219. ui.tree_Model.column = [1, tree_color];
  1220. CheckCtrlProcess();
  1221. // console.log(model.global_ctrl);
  1222. return old_data;
  1223. }
  1224. //创建工作区
  1225. function CreateWorkArea(name) {
  1226. let tree_color = [];
  1227. console.log("1111");
  1228. HideWorkcondition();
  1229. console.log("2222");
  1230. model.acax_app.control.workArea.Append(name);
  1231. let cur_id;
  1232. model.acax_app.view.RenderTree(() => {
  1233. g_cur_id2index_cache = {};
  1234. g_cur_index2id_cache = {};
  1235. }, info=>{
  1236. let icon = "";
  1237. let color = "";
  1238. //设置id
  1239. let cur_check_state = 0;
  1240. let cur_type = model.acax_app.path.Type(info.index);
  1241. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1242. cur_check_state = 3;
  1243. }
  1244. if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1245. cur_check_state = 2;
  1246. }
  1247. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1248. tree_color.push("");
  1249. }
  1250. let id2index = g_cur_id2index_cache;
  1251. let index2id = g_cur_index2id_cache;
  1252. let index = info.index;
  1253. let id = info.id;
  1254. //赋予图标
  1255. if(CheckPicture(cur_type)){
  1256. icon = CheckPicture(cur_type);
  1257. }
  1258. if(index) {
  1259. id2index[id] = index;
  1260. index2id[index] = id;
  1261. }
  1262. if("workArea" === info.name) {
  1263. cur_id = info.id;
  1264. }
  1265. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1266. color = "#bbbbbb";
  1267. }
  1268. //获取约束颜色
  1269. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1270. color = model.acax_app.model.constrain.Get(info.name).color;
  1271. }
  1272. //将第一个节点设为无选择框
  1273. if(info.id === 1) {
  1274. cur_check_state = 3;
  1275. icon = "form";
  1276. }
  1277. return {
  1278. name : info.name,
  1279. icon : icon,
  1280. id : info.id,
  1281. check_state : cur_check_state,
  1282. color : color
  1283. };
  1284. },
  1285. tree=>{
  1286. tree_color = getTreeColorsInOrder(tree);
  1287. ui.tree_Model.tree = tree;
  1288. });
  1289. ui.tree_Model.position = cur_id;
  1290. //渲染3d模型
  1291. unit.form.mainfrm.ClearCanvas();
  1292. ui.tree_Model.column = [1, tree_color];
  1293. CheckCtrlProcess();
  1294. }
  1295. //创建工程
  1296. function CreateProject(name) {
  1297. let tree_color = [];
  1298. //隐藏掉旧的工况
  1299. HideWorkcondition();
  1300. model.acax_app.control.project.Create(name);
  1301. let cur_name = model.acax_app.model.project.Current();
  1302. let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
  1303. let cur_id;
  1304. model.acax_app.view.RenderTree(() => {
  1305. g_cur_id2index_cache = {};
  1306. g_cur_index2id_cache = {};
  1307. }, info=>{
  1308. let icon = "";
  1309. let color = "";
  1310. //设置id
  1311. let cur_check_state = 0;
  1312. let cur_type = model.acax_app.path.Type(info.index);
  1313. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1314. cur_check_state = 3;
  1315. }
  1316. if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1317. cur_check_state = 2;
  1318. }
  1319. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1320. tree_color.push("");
  1321. }
  1322. let id2index = g_cur_id2index_cache;
  1323. let index2id = g_cur_index2id_cache;
  1324. let index = info.index;
  1325. let id = info.id;
  1326. //赋予图标
  1327. if(CheckPicture(cur_type)){
  1328. icon = CheckPicture(cur_type);
  1329. }
  1330. if(index) {
  1331. id2index[id] = index;
  1332. index2id[index] = id;
  1333. }
  1334. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
  1335. cur_id = info.id;
  1336. }
  1337. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1338. color = "#bbbbbb";
  1339. }
  1340. //获取约束颜色
  1341. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1342. color = model.acax_app.model.constrain.Get(info.name).color;
  1343. }
  1344. //将第一个节点设为无选择框
  1345. if(info.id === 1) {
  1346. cur_check_state = 3;
  1347. icon = "form";
  1348. }
  1349. return {
  1350. name : info.name,
  1351. icon : icon,
  1352. id : info.id,
  1353. check_state : cur_check_state,
  1354. color : color
  1355. };
  1356. },
  1357. tree=>{
  1358. tree_color = getTreeColorsInOrder(tree);
  1359. ui.tree_Model.tree = tree;
  1360. });
  1361. ui.tree_Model.position = cur_id;
  1362. //渲染3d模型
  1363. if(model.acax_app.model.project.GetModel().step === "unimported") {
  1364. unit.form.mainfrm.ClearCanvas();
  1365. }
  1366. ui.tree_Model.column = [1, tree_color];
  1367. CheckCtrlProcess();
  1368. }
  1369. //导入模型
  1370. function OnOpenStepFile() {
  1371. if(model.global_ctrl[0] && model.global_ctrl[1] ) {
  1372. var model_file = myArray[parseFloat(ui.listbox.index)];
  1373. model.acax_app.control.ImportStep(model_file, (model_file, model_plyfile)=>{
  1374. model.acax_app.view.Render3D(info=>{
  1375. unit.form.mainfrm.OnloadModel(info.model3d.step);
  1376. });
  1377. }
  1378. );
  1379. }else{
  1380. unit.form.mainfrm.OnCueline('未创建工程', 'red');
  1381. return;
  1382. }
  1383. }
  1384. //插入新子节点
  1385. function findAndAppendByName(json, targetName, newChild) {
  1386. if (json.name === targetName) {
  1387. // 拼接新的 JSON 数据
  1388. if (!json.children) {
  1389. json.children = [];
  1390. }
  1391. json.children.unshift(newChild);
  1392. return true; // 找到后返回 true
  1393. }
  1394. // 遍历子节点递归查找
  1395. if (json.children) {
  1396. for (const child of json.children) {
  1397. if (findAndAppendByName(child, targetName, newChild)) {
  1398. return true; // 如果找到目标节点,结束递归
  1399. }
  1400. }
  1401. }
  1402. return false; // 没找到返回 false
  1403. }
  1404. //给面节点改名字并添加check_state属性
  1405. function updateJsonNodes(jsonData) {
  1406. let count = 1; // 用于计数生成 Face1, Face2...
  1407. //let count_id = 100000;
  1408. function traverse(node) {
  1409. // 为每个节点添加 check_state: 2 属性
  1410. node.check_state = 3;
  1411. node.icon = '';
  1412. node.r_id = node.id;
  1413. node.id = node.faceId;
  1414. //node.id = ++count_id;
  1415. if(node.id === 100001) {
  1416. node.icon = 'model2';
  1417. }else if(node.id === 100002) {
  1418. node.icon = 'model3';
  1419. }
  1420. // 如果存在 children 属性,则递归处理
  1421. if (node.children && Array.isArray(node.children)) {
  1422. for (let child of node.children) {
  1423. traverse(child); // 递归遍历子节点
  1424. }
  1425. } else if (node.name && node.name.startsWith("Face_")) {
  1426. // 修改 name 值为 Face1, Face2...
  1427. node.name = `Face${count}`;
  1428. node.icon = 'face';
  1429. count++;
  1430. }
  1431. }
  1432. traverse(jsonData);
  1433. return jsonData;
  1434. }
  1435. //查找模型的第一个节点值获取id
  1436. function getFirstId(obj) {
  1437. // 检查是否有 children 并提取第一个节点的 id
  1438. if (obj.children && obj.children.length > 0) {
  1439. return obj.children[0].id;
  1440. }
  1441. return null; // 如果没有子节点,返回 null
  1442. }
  1443. // 深度优先遍历函数
  1444. function getTreeColorsInOrder(tree) {
  1445. // 定义存储颜色的数组
  1446. const tree_color = [];
  1447. // 定义递归函数
  1448. function dfs(node) {
  1449. // 如果当前节点有 color 属性,则加入数组
  1450. if (node.color !== undefined) {
  1451. tree_color.push(node.color);
  1452. }
  1453. // 按顺序遍历子节点
  1454. if (node.children && node.children.length > 0) {
  1455. node.children.forEach(child => dfs(child));
  1456. }
  1457. }
  1458. // 调用递归函数,传入根节点
  1459. dfs(tree);
  1460. // 返回颜色数组
  1461. return tree_color;
  1462. }
  1463. //将模型颜色存成map
  1464. function getTreeIdColorMap(tree) {
  1465. // 定义存储 id 和 color 的对象
  1466. const idColorMap = {};
  1467. // 定义递归函数
  1468. function dfs(node) {
  1469. // 检查当前节点的 name 属性是否包含 "face",以及是否具有 id 和 color 属性
  1470. if (node.name && node.name.includes("Face") && node.id !== undefined && node.color !== undefined) {
  1471. idColorMap[node.id] = node.color;
  1472. }
  1473. // 如果存在子节点,递归遍历
  1474. if (node.children && node.children.length > 0) {
  1475. node.children.forEach(child => dfs(child));
  1476. }
  1477. }
  1478. // 调用递归函数,传入根节点
  1479. dfs(tree);
  1480. // 返回存储的 id 和 color 键值对对象
  1481. return idColorMap;
  1482. }
  1483. //获取模型面的颜色保存到project
  1484. function SetModelColor(Idx) {
  1485. let model_color = getTreeIdColorMap(Idx);
  1486. let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
  1487. let model_prop = model.acax_app.view.GetProperty(cut_project_index);
  1488. if(model_prop === undefined) {
  1489. model_prop = {};
  1490. model_prop.color = model_color;
  1491. model.acax_app.view.SetProperty(cut_project_index, model_prop);
  1492. }else{
  1493. model_prop.color = model_color;
  1494. model.acax_app.view.SetProperty(cut_project_index, model_prop);
  1495. }
  1496. //console.log(model.acax_app.view.GetProperty(cut_project_index));
  1497. }
  1498. //将颜色给模型赋回去
  1499. function assignColorsToTree(tree, idColorMap) {
  1500. // 定义递归函数
  1501. function dfs(node) {
  1502. // 如果当前节点的 id 存在于 idColorMap 中,赋值回 color
  1503. if (node.id !== undefined && idColorMap[node.id] !== undefined) {
  1504. node.color = idColorMap[node.id];
  1505. }
  1506. // 按顺序遍历子节点
  1507. if (node.children && node.children.length > 0) {
  1508. node.children.forEach(child => dfs(child));
  1509. }
  1510. }
  1511. // 调用递归函数,传入根节点
  1512. dfs(tree);
  1513. // 返回更新后的树
  1514. return tree;
  1515. }
  1516. //找记录颜色和生成颜色不同的键值对
  1517. function findDifferences(oldMap, newMap) {
  1518. const differences = {};
  1519. for (const key in oldMap) {
  1520. if (oldMap[key] !== newMap[key]) {
  1521. differences[key] = newMap[key];
  1522. }
  1523. }
  1524. return differences;
  1525. }
  1526. var difference = {};
  1527. //获取工程中颜色,为模型涂色
  1528. function SetUserColor() {
  1529. var dif_key = Object.keys(difference);
  1530. console.log(dif_key.length);
  1531. for(let i = 0;i < dif_key.length;++i) {
  1532. let rgb = hexToRgb(difference[dif_key[i]]);
  1533. try {
  1534. unit.form.mainfrm.LightFace(dif_key[i], rgb); // 调用设置颜色
  1535. } catch (error) {
  1536. console.error(`Failed to apply color for key ${dif_key[i]}`, error);
  1537. }
  1538. }
  1539. }
  1540. //导入模型树节点
  1541. function OnTree(Idx){
  1542. let tree_color = [];
  1543. //console.log(JSON.stringify(Idx, null, 2));
  1544. updateJsonNodes(Idx);
  1545. //模型树颜色
  1546. let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
  1547. if(model.acax_app.view.GetProperty(cut_project_index) !== undefined ) {
  1548. //获取工程中的模型颜色,为树赋颜色
  1549. if(model.acax_app.view.GetProperty(cut_project_index).color!==undefined ) {
  1550. var old_map = getTreeIdColorMap(Idx);
  1551. //console.log(old_map);
  1552. //console.log(model.acax_app.view.GetProperty(cut_project_index).color);
  1553. difference = findDifferences(old_map, model.acax_app.view.GetProperty(cut_project_index).color);
  1554. //console.log(difference);
  1555. assignColorsToTree(Idx, model.acax_app.view.GetProperty(cut_project_index).color);
  1556. }
  1557. }else{
  1558. SetModelColor(Idx);
  1559. }
  1560. model.acax_app.view.RenderTree(() => {
  1561. g_cur_id2index_cache = {};
  1562. g_cur_index2id_cache = {};
  1563. }, info=>{
  1564. let icon = "";
  1565. //设置id
  1566. let color = "";
  1567. let cur_check_state = 0;
  1568. let cur_type = model.acax_app.path.Type(info.index);
  1569. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1570. cur_check_state = 3;
  1571. }
  1572. if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1573. cur_check_state = 2;
  1574. }
  1575. let id2index = g_cur_id2index_cache;
  1576. let index2id = g_cur_index2id_cache;
  1577. let index = info.index;
  1578. let id = info.id;
  1579. //赋予图标
  1580. if(CheckPicture(cur_type)){
  1581. icon = CheckPicture(cur_type);
  1582. }
  1583. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1584. color = "#bbbbbb";
  1585. }
  1586. //获取约束颜色
  1587. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1588. color = model.acax_app.model.constrain.Get(info.name).color;
  1589. }
  1590. if(index) {
  1591. id2index[id] = index;
  1592. index2id[index] = id;
  1593. }
  1594. //将第一个节点设为无选择框
  1595. if(info.id === 1) {
  1596. cur_check_state = 3;
  1597. icon = "form";
  1598. }
  1599. return {
  1600. name : info.name,
  1601. icon : icon,
  1602. id : info.id,
  1603. check_state : cur_check_state,
  1604. color : color
  1605. };
  1606. },
  1607. tree => {
  1608. //从工程中获取保存的model数据
  1609. //插入模型树节点与工程节点进行拼接
  1610. let pro_Index= model.acax_app.view.GetCurrentProjectIndex();
  1611. let pro_name = model.acax_app.path.Name(pro_Index);
  1612. findAndAppendByName(tree, pro_name, Idx);
  1613. //将模型树节点与工程节点拼接后保存到model中
  1614. let pro_model = model.acax_app.model.project.GetModel();
  1615. pro_model.pro_model = Idx;
  1616. model.acax_app.model.project.SetModel(pro_model);
  1617. tree_color = getTreeColorsInOrder(tree);
  1618. ui.tree_Model.tree = tree;
  1619. }
  1620. );
  1621. ui.tree_Model.column = [1, tree_color];
  1622. ui.tree_Model.position = getFirstId(Idx);
  1623. //表示模型已导入
  1624. model.global_ctrl[2] = true;
  1625. }
  1626. //创建工况
  1627. function CreateWorkCondition(name){
  1628. let tree_color = [];
  1629. //隐藏掉旧的工况
  1630. HideWorkcondition();
  1631. let condition_index = model.acax_app.control.workCondition.Create(name);
  1632. let cur_name = model.acax_app.model.workCondition.Current();
  1633. let cur_index = model.acax_app.view.GetCurrentProjectIndex();
  1634. let cur_id;
  1635. //console.log(model.acax_app.path.Parent(cur_index, 2) === model.acax_app.view.GetCurrentProjectIndex());
  1636. model.acax_app.view.RenderTree(() => {
  1637. g_cur_id2index_cache = {};
  1638. g_cur_index2id_cache = {};
  1639. }, info=>{
  1640. let icon = "";
  1641. let color = "";
  1642. //设置id
  1643. let cur_check_state = 0;
  1644. let cur_type = model.acax_app.path.Type(info.index);
  1645. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1646. cur_check_state = 3;
  1647. }
  1648. if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1649. cur_check_state = 2;
  1650. }
  1651. let id2index = g_cur_id2index_cache;
  1652. let index2id = g_cur_index2id_cache;
  1653. let index = info.index;
  1654. let id = info.id;
  1655. //赋予图标
  1656. if(CheckPicture(cur_type)){
  1657. icon = CheckPicture(cur_type);
  1658. }
  1659. if(index) {
  1660. id2index[id] = index;
  1661. index2id[index] = id;
  1662. }
  1663. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 2) === cur_index)) {
  1664. cur_id = info.id;
  1665. }
  1666. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1667. color = "#bbbbbb";
  1668. }
  1669. //获取约束颜色
  1670. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1671. color = model.acax_app.model.constrain.Get(info.name).color;
  1672. }
  1673. //将第一个节点设为无选择框
  1674. if(info.id === 1) {
  1675. cur_check_state = 3;
  1676. icon = "form";
  1677. }
  1678. return {
  1679. name : info.name,
  1680. icon : icon,
  1681. id : info.id,
  1682. check_state : cur_check_state,
  1683. color : color
  1684. };
  1685. },
  1686. tree => {
  1687. //获取当前工程的名字
  1688. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  1689. let pro_name = model.acax_app.path.Name(pro_Index);
  1690. //模型存在在加载
  1691. if(model.acax_app.model.project.GetModel().pro_model) {
  1692. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  1693. findAndAppendByName(tree, pro_name, cur_model);
  1694. }
  1695. //赋值给dcip的树结构
  1696. tree_color = getTreeColorsInOrder(tree);
  1697. ui.tree_Model.tree = tree;
  1698. }
  1699. );
  1700. ui.tree_Model.position = cur_id;
  1701. ui.tree_Model.column = [1, tree_color];
  1702. }
  1703. //创建材料属性
  1704. function CreateMaterial(mat) {
  1705. let tree_color = [];
  1706. model.acax_app.control.materialProp.Create(mat);
  1707. let cur_name = model.acax_app.model.materialProp.Current();
  1708. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  1709. let cur_id;
  1710. model.acax_app.view.RenderTree(() => {
  1711. g_cur_id2index_cache = {};
  1712. g_cur_index2id_cache = {};
  1713. }, info=>{
  1714. let icon = "";
  1715. let color = "";
  1716. //设置id
  1717. let cur_check_state = 0;
  1718. let cur_type = model.acax_app.path.Type(info.index);
  1719. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1720. cur_check_state = 3;
  1721. }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1722. cur_check_state = 2;
  1723. }
  1724. let id2index = g_cur_id2index_cache;
  1725. let index2id = g_cur_index2id_cache;
  1726. let index = info.index;
  1727. let id = info.id;
  1728. //赋予图标
  1729. if(CheckPicture(cur_type)){
  1730. icon = CheckPicture(cur_type);
  1731. }
  1732. if(index) {
  1733. id2index[id] = index;
  1734. index2id[index] = id;
  1735. }
  1736. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  1737. cur_id = info.id;
  1738. }
  1739. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1740. color = "#bbbbbb";
  1741. }
  1742. //获取约束颜色
  1743. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1744. color = model.acax_app.model.constrain.Get(info.name).color;
  1745. }
  1746. //将第一个节点设为无选择框
  1747. if(info.id === 1) {
  1748. cur_check_state = 3;
  1749. icon = "form";
  1750. }
  1751. return {
  1752. name : info.name,
  1753. icon : icon,
  1754. id : info.id,
  1755. check_state : cur_check_state,
  1756. color : color
  1757. };
  1758. },
  1759. tree => {
  1760. //获取当前工程的名字
  1761. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  1762. let pro_name = model.acax_app.path.Name(pro_Index);
  1763. if(model.acax_app.model.project.GetModel().pro_model) {
  1764. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  1765. findAndAppendByName(tree, pro_name, cur_model);
  1766. }
  1767. //赋值给dcip的树结构
  1768. tree_color = getTreeColorsInOrder(tree);
  1769. ui.tree_Model.tree = tree;
  1770. }
  1771. );
  1772. //将材料属性添加到模型信息中
  1773. model.acax_app.view.Render3D(info=>{
  1774. console.log(info.materialProps);
  1775. info.materialProps.push(mat);
  1776. console.log("2222222");
  1777. });
  1778. ui.tree_Model.position = cur_id;
  1779. ui.tree_Model.column = [1, tree_color];
  1780. model.global_ctrl[5] = true;
  1781. }
  1782. //修改材料面板属性属性
  1783. function ModifyMaterial(material) {
  1784. //获取当前材料的名字
  1785. let material_name = model.acax_app.model.materialProp.Current();
  1786. model.acax_app.control.materialProp.Set(material, material_name);
  1787. unit.form.mainfrm.OnCueline('修改成功', 'green');
  1788. }
  1789. //创建载荷
  1790. function CreateBoundary(Load, name) {
  1791. console.log(model.global_ctrl);
  1792. if(!model.global_ctrl[0] || !model.global_ctrl[1] || !model.global_ctrl[2] || !model.global_ctrl[3]) {
  1793. unit.form.mainfrm.OnCueline('未满足创建条件', 'red');
  1794. return;
  1795. }
  1796. let tree_color = [];
  1797. let load = model.acax_app.control.constrain.Create(Load, name);
  1798. let cur_name = model.acax_app.model.constrain.Current();
  1799. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  1800. var cur_id;
  1801. model.acax_app.view.RenderTree(() => {
  1802. g_cur_id2index_cache = {};
  1803. g_cur_index2id_cache = {};
  1804. }, info=>{
  1805. let icon = "";
  1806. let color = "";
  1807. //设置id
  1808. let cur_check_state = 0;
  1809. let cur_type = model.acax_app.path.Type(info.index);
  1810. if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
  1811. cur_check_state = 3;
  1812. }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
  1813. cur_check_state = 2;
  1814. }
  1815. let id2index = g_cur_id2index_cache;
  1816. let index2id = g_cur_index2id_cache;
  1817. let index = info.index;
  1818. let id = info.id;
  1819. //赋予图标
  1820. if(CheckPicture(cur_type)){
  1821. icon = CheckPicture(cur_type);
  1822. }
  1823. if(index) {
  1824. id2index[id] = index;
  1825. index2id[index] = id;
  1826. }
  1827. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  1828. cur_id = info.id;
  1829. cur_check_state = 2;
  1830. }
  1831. if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
  1832. color = "#bbbbbb";
  1833. }
  1834. //获取约束颜色
  1835. if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
  1836. color = model.acax_app.model.constrain.Get(info.name).color;
  1837. }
  1838. //将第一个节点设为无选择框
  1839. if(info.id === 1) {
  1840. cur_check_state = 3;
  1841. icon = "form";
  1842. }
  1843. return {
  1844. name : info.name,
  1845. icon : icon,
  1846. id : info.id,
  1847. check_state : cur_check_state,
  1848. color : color
  1849. };
  1850. },
  1851. tree => {
  1852. //获取当前工程的名字
  1853. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  1854. let pro_name = model.acax_app.path.Name(pro_Index);
  1855. if(model.acax_app.model.project.GetModel().pro_model) {
  1856. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  1857. findAndAppendByName(tree, pro_name, cur_model);
  1858. }
  1859. //赋值给dcip的树结构
  1860. tree_color = getTreeColorsInOrder(tree);
  1861. ui.tree_Model.tree = tree;
  1862. }
  1863. );
  1864. //将载荷属性添加到模型信息中
  1865. ui.tree_Model.position = cur_id;
  1866. //console.log(tree_color);
  1867. ui.tree_Model.column = [1, tree_color];
  1868. model.acax_app.view.Render3D(info=>{
  1869. info.constrains.push(Load);
  1870. });
  1871. }
  1872. //修改载荷面板属性
  1873. function ModifyConstraint(constrain) {
  1874. let constrain_name = model.acax_app.model.constrain.Current();
  1875. model.acax_app.control.constrain.Set(constrain, constrain_name);
  1876. unit.form.mainfrm.OnCueline('修改成功', 'green');
  1877. }
  1878. function OnMessage(idx){
  1879. ui.cueline.value += idx + '\n';
  1880. ui.cueline.row = -1;
  1881. }
  1882. function OnChangeMenu(Idx){
  1883. ui.tree_menu.index = parseInt(Idx);
  1884. }
  1885. function OnDeleteFile() {
  1886. myArray.splice(parseFloat(ui.listbox.index), 1);
  1887. ui.listbox.list = [
  1888. myArray
  1889. ];
  1890. }
  1891. function OnOpenFile(){
  1892. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Step Files(*.step *.stp);;Iges Files(*.iges *.igs);;Nastran Files(*.nas)");
  1893. model.write(fname, model.getCurrentDirectory() + '/data/address.txt');
  1894. myArray.push(fname);
  1895. ui.listbox.list = [
  1896. myArray
  1897. ];
  1898. }
  1899. function OnChangeOptions(){
  1900. options = !options;
  1901. ui.stack_options.visible = options;
  1902. }
  1903. function OnTopMenu(idx) {
  1904. ui.stack_import.visible = true;
  1905. ui.stack_import.index = parseInt(idx) - 1;
  1906. ui.pb_import01.valid = ui.pb_import02.valid = ui.pb_import03.valid = ui.pb_import04.valid = ui.pb_import05.valid = false;
  1907. //model.ide_info(idx);
  1908. if (parseInt(idx) === 1) {
  1909. ui.pb_import01.valid = true;
  1910. }
  1911. if (parseInt(idx) === 2) {
  1912. ui.pb_import02.valid = true;
  1913. }
  1914. if (parseInt(idx) === 3) {
  1915. ui.pb_import03.valid = true;
  1916. }
  1917. if (parseInt(idx) === 4) {
  1918. ui.pb_import04.valid = true;
  1919. }
  1920. if (parseInt(idx) === 5) {
  1921. ui.pb_import05.valid = true;
  1922. }
  1923. }
  1924. //The message corresponding callback executed by the docker pane.
  1925. // when calling [side_pane].fireEvent(type,para) in the main form.
  1926. function OnParentDockerMessage(type, para) {
  1927. }
  1928. //////////////////////////////////////////////////////////////////////////
  1929. // Utils Functions.
  1930. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  1931. function onDragFile(filepath) {
  1932. }
  1933. function PUI(cb) {
  1934. if(pui){cb();}
  1935. }
  1936. /*Usage of BLOCK_EVENT
  1937. BLOCK_EVENT(()=>{
  1938. ui.[name].[var] = ...;
  1939. });
  1940. */
  1941. function BLOCK_EVENT(cb) {
  1942. ui.block_event = true;
  1943. cb();
  1944. ui.block_event = false;
  1945. }
  1946. //////////////////////////////////////////////////////////////////////////
  1947. // template codes for cw callback js.
  1948. function CW_DeclareVariable(name, setter, getter) {
  1949. if(typeof(__DeclareVariable) === 'function') {
  1950. __DeclareVariable(name, setter, getter);
  1951. }
  1952. }
  1953. function CW_DeclareOuterVariable(name) {
  1954. if(typeof(__DeclareOuterVariable) === 'function') {
  1955. __DeclareOuterVariable(name);
  1956. }
  1957. }