12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168 |
- ////////////////////////////////////////////////////////////////////////////
- // System Pre-define Functions
- // 95099372-ef3e-11ea-9c81-bf848405c62e
- //Callback of data preparation stage before UI is fully loaded.
- //dcip节点和模型树节点对应值
- var g_cur_id2index_cache = {};
- var g_cur_index2id_cache = {};
- //记录已加载工况
- var workcondition = [];
- function OnInitializeData(reload, preview) {
-
- PUI(()=>{
- //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
- //The 'pui' variable is valid in all functions of this document.
- //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
-
- });
- ui.tree_menu.index = 2;
- ui.tree_Model.title = ['Part Assemblies/Parts', 'Color', 'UID'];
- }
- //Callback after UI is fully loaded and displayed.
- function OnReady(reload, preview) {
-
- PUI(()=>{
- //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
- //The 'pui' variable is valid in all functions of this document.
- //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
-
- });
- }
- function OnCloseForm() {
- }
- function OnException(err) {
- //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
- }
- var options = true;
- let myArray = [];
- //////////////////////////////////////////////////////////////////////////
- // Callback Functions.
- // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
- //测试函数
- function OnTest(){
- //GenerateFile();
- // console.log(model.acax_app.path.Name(g_cur_id2index_cache["131"]));
- //console.log(g_cur_id2index_cache);
- // console.log(g_cur_index2id_cache);
- //console.log(model.acax_app.model.materialProp.Current());
- //SetUserColor();
- let str = unit.form.mainfrm.findRIdById(model.acax_app.model.project.GetModel().pro_model, 100005);
- console.log(str);
- console.log(comx.occio.GetFacePoint(comx.occore.GetEntryEx(), str));
-
- }
- //判断工作流程
- function CheckCtrlProcess() {
- for(let i = 0 ;i < 6;++i) {
- model.global_ctrl[i] = false;
- }
- //工作区
- if(model.acax_app.model.workArea.Current() !== false) {
- model.global_ctrl[0] = true;
- }else{
- return;
- }
- //工程
- if(model.acax_app.model.project.Current() !== "") {
- model.global_ctrl[1] = true;
- }else{
- return;
- }
- //获取模型存在否
-
- if( model.acax_app.model.project.GetModel().step !== "unimported") {
- model.global_ctrl[2] = true;
- }else{
- return;
- }
- //工况
- if(model.acax_app.model.workCondition.Current() !== "") {
- model.global_ctrl[3] = true;
- }else{
- return;
- }
- //BBP
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
-
- if(model_prop === undefined ) {
-
- model.global_ctrl[4] = false;
- }else if(model_prop.BPP){
- model.global_ctrl[4] = true;
- }
- //材料
- if(model.acax_app.model.materialProp.Current()) {
- model.global_ctrl[5] = true;
- }
- }
- //生成随机颜色
- function getRandomHexColor() {
- // 随机生成一个 0 到 16777215 之间的整数,并转换为十六进制字符串
- let color = Math.floor(Math.random() * 16777216).toString(16);
- // 确保颜色代码始终为 6 位
- return "#" + color.padStart(6, "0");
- }
- //生成求解文件
- function GenerateFile() {
-
- model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + model.acax_app.model.project.GetModel().step.replace(/\\/g, "/") + " " + model.getCurrentDirectory(), cb => {
- console.log(cb);
- });
- model.acax_app.control.Export(info=>{
- //console.log(JSON.stringify(info, null, 2));
-
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- var File = ['结构静力学前处理文件', '\n$ address', info.model3d.step.replace(/\\/g, "/")];
- //添加材料
- File.push("\n$ materials");
- 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]["屈服强度"];
- File.push(str);
- //添加BPP
- File.push("\n$ BPP");
- File.push(model.acax_app.view.GetProperty(cut_workcondition_index).BPP.BPP);
- //brepFiles
- File.push("\n$ brepFiles");
- //需要brepFiles文件
- let brep_data = model.acax_app.view.GetProperty(cut_workcondition_index).brep;
- let brep_arr = Object.keys(brep_data);
- for(let i = 0;i < brep_arr.length;++i) {
- File.push(brep_data[brep_arr[i]].brep);
- }
-
- //forceFace未实现
- File.push("\n$ forceFace id xn yn zn xr yr zr");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "分布载荷压力" && info.cons_list[i]["位置标记"][0] === 'F' ) {
- let str0 = info.cons_list[i]["位置标记"].split(" ");
- 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"];
- File.push(str1);
- }
- }
- //fixFace未实现
- File.push("\n$ fixFace id xn yn zn xr yr zr");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'F' ) {
- let str0 = info.cons_list[i].type.split(" ");
- 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"];
- File.push(str1);
- }
- }
-
- //添加梁和梁节点
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "梁") {
- File.push("\n$ mat poi radius len seg Beam");
- let str1 = info.cons_list[i]["弹性模量"] + " " + info.cons_list[i]["泊松比"] + " " + info.cons_list[i]["梁约束参数半径"] + " " +info.cons_list[i]["梁约束参数长度"] + " " + info.cons_list[i]["梁约束参数个数"];
- File.push(str1);
- let len = info.cons_list[i]["梁约束参数个数"];
- File.push("\n$ x y z Beam");
- for(let j = 0 ; j <= len ;++j){
- 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];
- File.push(str);
- }
- }
-
- }
- //添加固定支撑
- File.push("\n$ con ids id xd yd zd xr yr zr Beam");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') {
- let str0 = info.cons_list[i].type.split(" ");
- 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"];
- File.push(str1);
- }
- }
- //添加arrow
- File.push("\n$ arrow ids id xn yn zn xr yr zr Beam");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') {
- let str0 = info.cons_list[i].type.split(" ");
- 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"];
- File.push(str1);
- }
- }
- //添加弹簧
- File.push("\n$ x y z X Y Z stiffness_x stiffness_y stiffness_z type1 type2 Spring");
- for(let i = 0;i < info.cons_list.length;++i ) {
- 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')) {
- 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];
- File.push(str1);
- }
- }
- //添加连接
- File.push("\n$ type id1 id x1 y1 z1 type id1 id x2 y2 z2 xn yn zn xr yr zr Connect");
- for(let i = 0;i < info.cons_list.length;++i ) {
- 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')) {
- 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"];
- File.push(str1);
- }
- }
-
- //添加rb3
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "rb3") {
- File.push("\n$ id RB3");
- let str1 = info.cons_list[i]["编号"];
- str1 = str1.split(" ");
- //console.log(str1);
- for(let j = 0;j < str1.length;++j) {
- if(str1[j] !== '') {
- File.push(str1[j]);
- }
-
- }
-
- File.push("\n$ type id ids x y z RB3");
- let str = info.cons_list[i].types + " " +info.cons_list[i].x + " " + info.cons_list[i].y + " " + info.cons_list[i].z;
- File.push(str);
-
- }
-
- }
- //集中载荷rb3
- File.push("\n$ arrow type id ids xn yn zn xr yr zr RB3");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "集中载荷压力" && info.cons_list[i]["位置标记"][0] === 'P' ) {
-
- 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"];
- File.push(str1);
- }
- }
- //固定支撑rb3
- File.push("\n$ fix type id ids xn yn zn xr yr zr RB3");
- for(let i = 0;i < info.cons_list.length;++i ) {
- if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'P') {
- 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"];
- File.push(str1);
- }
- }
- model.writeFile(File);
-
- });
- }
- function OnTest1(){
- console.log(model.acax_app.model.project.GetModel());
- //console.log(model.acax_app.model.constrain.Database());
- //GenerateFile() ;
- //console.log(model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()));
- }
- //创建约束显示
- function CreateContrainShow() {
- //console.log(model.acax_app.model.workArea.Current() !== false);
- //console.log(model.acax_app.model.project.Current() !== "");
- //console.log(model.acax_app.model.workCondition.Current() !== "");
- if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){
- //获取工况数据库
- //console.log(workcondition);
- var new_arr_key ;
- var constrain_data;
- if(model.acax_app.model.workCondition.Current() === "") {
- new_arr_key = [];
- }else{
- constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
- if(Object.keys(constrain_data.constrain.db).length !== 0) {
- new_arr_key = Object.keys(constrain_data.constrain.db);
- }else{
- new_arr_key = [];
- }
- }
- //查看当前工程工况是否已加载
- const path1 = model.acax_app.model.workArea.Current();
- const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1);
- var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current();
- var flag = 1;
- console.log(workcondition.includes(cur_name));
- if(workcondition.includes(cur_name)) {
- for(let i = 0;i < new_arr_key.length;++i) {
- let type = constrain_data.constrain.db[new_arr_key[i]].cons_type;
- unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[new_arr_key[i]].unique, false);
- if(type === "rb3" && flag) {
- unit.form.mainfrm.HideAndShow("pick", "rb3", false);
- flag = 0;
- }
- }
- ShowPoints();
- ShowMarks();
- }else{
- for(let i = 0;i < new_arr_key.length;++i) {
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "集中载荷压力") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "固定支撑") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "梁") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "连接") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "弹簧") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "分布载荷压力") {
- 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);
- }
- if(constrain_data.constrain.db[new_arr_key[i]].constraint === "rb3") {
- unit.form.mainfrm.OnGenerateGuass(constrain_data.constrain.db[new_arr_key[i]]["编号"]);
- 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);
- }
- }
- //加载点
- OnLoadPoints();
- OnLoadMarks();
- workcondition.push(cur_name);
-
- }
- }
-
- }
- //已创建但被隐藏,显示点
- function ShowPoints() {
- console.log("1111");
- let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
- let point_model = model.acax_app.view.GetProperty(work_condition).point;
- let point_arr = Object.keys(point_model);
- for(let i = 0;i < point_arr.length;++i) {
- unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, false);
- }
- }
- //已创建但被隐藏,显示Mark
- function ShowMarks() {
- let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
- let mark_model = model.acax_app.view.GetProperty(work_condition).mark;
- let mark_arr = Object.keys(mark_model);
- for(let i = 0;i < mark_arr.length;++i) {
- unit.form.mainfrm.HideAndShow("mark", mark_model[mark_arr[i]].name, false);
- }
- }
- //加载点
- function OnLoadPoints() {
- let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
- if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).point !== undefined ) {
- let point_model = model.acax_app.view.GetProperty(work_condition).point;
- let point_arr = Object.keys(point_model);
- for(let i = 0;i < point_arr.length;++i) {
- 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);
- }
- }
- }
- //加载Mark
- function OnLoadMarks() {
- let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex();
- if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).mark !== undefined ) {
- let mark_model = model.acax_app.view.GetProperty(work_condition).mark;
- let mark_arr = Object.keys(mark_model);
- for(let i = 0;i < mark_arr.length;++i) {
- 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);
- }
- }
- }
- //隐藏旧的工况
- function HideWorkcondition() {
- if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){
- let old_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- var point_model;
- var point_arr;
- if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).point === undefined) {
- point_model = {};
-
- }else{
- point_model = model.acax_app.view.GetProperty(old_workcondition_index).point;
-
- }
- point_arr = Object.keys(point_model);
-
- var mark_model;
- var mark_arr;
- if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).mark === undefined) {
- mark_model = {};
-
- }else{
- mark_model = model.acax_app.view.GetProperty(old_workcondition_index).mark;
-
- }
- mark_arr = Object.keys(mark_model);
-
- let constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
- var old_arr_key ;
- if(Object.keys(constrain_data.constrain.db).length !== 0) {
- old_arr_key = Object.keys(constrain_data.constrain.db);
- }else{
- old_arr_key = [];
- }
-
- //查看当前工程工况是否已加载
- const path1 = model.acax_app.model.workArea.Current();
- const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1);
- var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current();
- var flag = 1;
- if(workcondition.includes(cur_name)) {
- for(let i = 0;i <old_arr_key.length;++i ) {
- let type = constrain_data.constrain.db[old_arr_key[i]].cons_type;
- unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[old_arr_key[i]].unique, true);
- if(type === "rb3" && flag) {
- unit.form.mainfrm.HideAndShow("pick", "rb3", true);
- flag = 0;
- }
- }
- for(let i = 0;i < point_arr.length;++i) {
- unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, true);
- }
- for(let i = 0;i < mark_arr.length;++i) {
- unit.form.mainfrm.HideAndShow("mark", mark_model[mark_arr[i]].name, true);
- }
- }
- }
-
- }
- //获取当前工作区名称加当前工程名称加当前工况名称
- function GetCurUniqueName() {
- const path = model.acax_app.model.workArea.Database().list[0];
- const workarea_name =path.substring(path.lastIndexOf('/') + 1);
- const proj_name = model.acax_app.model.project.Current();
- const workcondition_name = model.acax_app.model.workCondition.Current();
- return workarea_name + proj_name + workcondition_name;
- }
- //生成Mark
- function SetMark(markss) {
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
- //console.log(model_prop);
- if(model_prop === undefined ) {
- model_prop = {};
- let mark = {};
- mark.mark1 = markss;
- model_prop.mark = mark;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }else if(model_prop.mark === undefined){
- let mark = {};
- mark.mark1 = markss;
- model_prop.mark = mark;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
- let len = Object.keys(model_prop.mark).length;
- let temp = "mark" + (len + 1);
- model_prop.mark[temp] = markss;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }
- //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
- }
- //生成点
- function SetPoint(node) {
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
- if(model_prop === undefined ) {
- model_prop = {};
- let point = {};
- point.point1 = node;
- //console.log(point);
- model_prop.point = point;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }else if(model_prop.point === undefined){
- let point = {};
- point.point1 = node;
- //console.log(point);
- model_prop.point = point;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
-
- let len = Object.keys(model_prop.point).length;
- let temp = "point" + (len + 1);
- model_prop.point[temp] = node;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }
- //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
-
- }
- //生成brep文件
- function SetBrepFile(brep_path){
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
- if(model_prop === undefined ) {
- model_prop = {};
- let brep = {};
- brep.brep1 = brep_path;
- //console.log(brep);
- model_prop.brep = brep;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }else if(model_prop.brep === undefined){
- let brep = {};
- brep.brep1 = brep_path;
- model_prop.brep = brep;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
- let brep_arr = Object.keys(model_prop.brep);
-
- var i = 0;
- for( i = 0;i < brep_arr.length;++i) {
- if(model_prop.brep[brep_arr[i]].brep === brep_path.brep) {
- break;
- }
- }
- if(i === brep_arr.length) {
- let temp = "brep" + (brep_arr.length + 1);
- model_prop.brep[temp] = brep_path;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }
-
- }
- //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
- }
- //生成BPP
- function SetBPPProperty(BPP) {
-
- let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
- if(model_prop === undefined) {
- model_prop = {};
- model_prop.BPP = BPP;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
- model_prop.BPP = BPP;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }
- model.global_ctrl[4] = true;
- }
- //修改约束属性的名字
- function ModifyConstraintName(new_name) {
-
- let tree_color = [];
- let cur_name = model.acax_app.model.constrain.Current();
- let flag = model.acax_app.control.constrain.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- if(flag === false) {
- unit.form.mainfrm.OnCueline('修改失败', 'red');
-
- }else{
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //从工程中获取保存的model数据
- if(model.acax_app.model.project.GetModel().pro_model){
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- ui.tree_Model.column = [1, tree_color];
- ui.tree_Model.position = cur_id;
- }
- //修改材料属性的名字
- function ModifyMaterialName(new_name) {
- let tree_color = [];
- let cur_name = model.acax_app.model.materialProp.Current();
- let flag = model.acax_app.control.materialProp.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- if(flag === true) {
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }else{
- unit.form.mainfrm.OnCueline('修改失败', 'red');
- }
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
- },
- tree => {
- //从工程中获取保存的model数据
- if(model.acax_app.model.project.GetModel().pro_model){
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
-
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- ui.tree_Model.column = [1, tree_color];
- ui.tree_Model.position = cur_id;
- }
- //修改的工程名
- function ModifyProName(new_name) {
- let tree_color = [];
- let cur_name = model.acax_app.path.Name(model.acax_app.view.GetCurrentProjectIndex());
- model.acax_app.model.project.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //从工程中获取保存的model数据
- if(model.acax_app.model.project.GetModel().pro_model){
- //获取当前工程的名字
-
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
-
- let pro_name = model.acax_app.path.Name(pro_Index);
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
-
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- ui.tree_Model.column = [1, tree_color];
- ui.tree_Model.position = cur_id;
- }
- //处理字符串截掉后五位
- function removeLastFiveCharacters(str) {
- str = String(str);
- if (str.length <= 5) {
- return ''; // 如果字符串长度小于等于 5,则返回空字符串
- }
- return str.substring(0, str.length - 5); // 提取从 0 到倒数第 5 位的子字符串
- }
- //点击弹出菜单
- function OnContentClick(){
- //获取一级子节点
- let str = removeLastFiveCharacters(ui.tree_Model.content_menu);
- let model_id = g_cur_id2index_cache[str];
- //let cur_name = model.acax_app.path.Name(model_id);
- switch (model.acax_app.path.Type(model_id)){
- case 2:
- //unit.form.Rename.Show();
- break;
- case 3:
- break;
- case 4:
- unit.form.RenameConstraint.Show();
- break;
- case 5:
- unit.form.RenameMaterial.Show();
- break;
- default:
- break;
- }
- }
- //右键单击树效果
- function OnRightClick(){
- let model_id = g_cur_id2index_cache[ui.tree_Model.position];
- switch (model.acax_app.path.Type(model_id)){
- case 2:
- /*ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];*/
- break;
- case 3:
- break;
- case 4:
- ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];
- break;
- case 5:
- ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];
- break;
- default:
- break;
- }
-
- }
- //点击树
- function OnClickTree(id, column, text){
- //获取模型树的对应节点
- let model_id = g_cur_id2index_cache[ui.tree_Model.position];
- let cur_workarea = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
- let cur_workcondition = model.acax_app.view.GetCurrentWorkConditionIndex();
- model.acax_app.view.RenderNode(model_id, info => {
- console.log(info);
- });
- switch (model.acax_app.path.Type(model_id)) {
- //切换工作区
- case 0:
- //不是当前工作区,切换工作区
- if(model_id !== cur_workarea){
- model.acax_app.view.RenderNode(model_id, info => {
- //隐藏工作区工况
- HideWorkcondition();
- OpenWorkArea(info.prop);
- //切换到当前工作区
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
-
- });
- }
- break;
- //选中材料库
- case 1:
-
- break;
- //切换工程
- case 2:
- //不是当前工程,切换工程
- if(model_id !== cur_proj){
- //隐藏掉旧的工况
- HideWorkcondition();
- model.acax_app.view.RenderNode(model_id, info => {
- //切换工程
- ChangePro(model.acax_app.path.Name(model_id));
- //切换到当前工程
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- //在canvas显示新的约束
- CreateContrainShow();
- });
- }
- break;
- //切换工况
- case 3:
- //不是当前工况,切换工况
- if(model_id !== cur_workcondition){
- model.acax_app.view.RenderNode(model_id, info => {
- //隐藏工况
- HideWorkcondition();
- //切换工况,旧的隐藏
- let old_data = ChangeWorkCondition(model.acax_app.path.Name(model_id));
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- //显示工况
- CreateContrainShow();
- });
-
- }
- break;
- //选中约束
- case 4:
- model.acax_app.view.RenderNode(model_id, info => {
- //切换到当前约束
- model.acax_app.model.constrain.SwitchTo(model.acax_app.path.Name(model_id));
- //将约束属性设置到对应面板
- ChangeConstraint(Object.values(info.prop)[0], info.prop);
- //切换点击约束
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- //渲染到3D模型
- if(ui.tree_Model.node.check_state === 2) {
-
- unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, false);
- console.log("show");
- }else if(ui.tree_Model.node.check_state === 0) {
-
- unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, true);
- console.log("hide");
-
- }
- });
- break;
- //选中材料属性
- case 5:
- model.acax_app.view.RenderNode(model_id, info => {
- //切换当前材料
- model.acax_app.model.materialProp.SwitchTo(model.acax_app.path.Name(model_id));
- unit.form.mainfrm.menu(3);
- unit.form.mainfrm.OnChangePicture(2, 1);
- unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
- //将材料属性设置到面板
- unit.form.mainfrm.setMaterial(info.prop);
- //切换到点击材料
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
- break;
- default:
- break;
- }
- if(column === 1) {
- var clr = ui.ColorDialog(text);
- let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
- let temp = model.acax_app.view.GetProperty(cut_project_index);
- temp.color[id] = clr;
- model.acax_app.view.SetProperty(cut_project_index, temp);
- let rgb = hexToRgb(clr);
- unit.form.mainfrm.LightFace(id, rgb);
- if(clr) {
- ui.tree_Model.column = [column, clr];
- }
- }
- }
- //16进制转rgb
- function hexToRgb(hex) {
- // 去掉前缀 #(如果有)
- hex = hex.replace(/^#/, '');
- // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB)
- if (hex.length === 3) {
- hex = hex.split('').map(char => char + char).join('');
- }
- // 解析 RGB 颜色值
- const r = parseInt(hex.slice(0, 2), 16);
- const g = parseInt(hex.slice(2, 4), 16);
- const b = parseInt(hex.slice(4, 6), 16);
- return { r, g, b };
- }
- //切换约束面板
- function ChangeConstraint(constraint_name, prop) {
- let constraint = {
- "固定支撑":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 0);
- // unit.form.mainfrm.OnChange
-
- unit.form.mainfrm.OnConChange(0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 0);
-
- unit.form.mainfrm.OnConChange(1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "弹簧":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 1);
-
- unit.form.mainfrm.OnConChange(1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "连接":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 2);
-
- unit.form.mainfrm.OnConChange(1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁(非均匀)":function(){
- },
- "集中载荷压力":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 0);
-
- unit.form.mainfrm.OnForceChange(0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "分布载荷压力":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 1);
-
- unit.form.mainfrm.OnForceChange(1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "rb3":function(){
- unit.form.mainfrm.OnChangeIndex(2);
- unit.form.mainfrm.menu(23);
-
- unit.form.mainfrm.setConstraint(prop);
- }
- };
-
- constraint[constraint_name]();
- }
- //判断图标
- function CheckPicture(idx) {
- switch (idx) {
- case 0:
- return "workarea";
- case 2:
- return "project";
- case 3:
- return "workcondition";
- case 4:
- return "constrain";
- case 5:
- return "materialproperty";
- default:
- return null; // 或者抛出一个错误,比如 `throw new Error("Invalid index");`
- }
- }
- //切换工作区
- function OpenWorkArea(fname) {
- let tree_color = [];
- fname = fname.replace(/\/+/g, "\\");
- var work_path = model.acax_app.model.workArea.List();
- //渲染模型树
- for(var i = 0;i < work_path.length;++i) {
- work_path[i] = work_path[i].replace(/\/+/g, "\\");
- if(fname === work_path[i]){
- model.acax_app.control.workArea.SwitchTo(i);
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }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())) {
- cur_check_state = 2;
- }
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- ui.tree_Model.column = [1, tree_color];
- }
- );
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- unit.form.mainfrm.SetColor(difference);
- CreateContrainShow();
- });
- }
-
- }
- }
-
- CheckCtrlProcess();
- console.log(model.global_ctrl);
- }
- //切换工程
- function ChangePro(pro_name) {
- let tree_color = [];
- model.acax_app.control.project.SwitchTo(pro_name);
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }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())) {
- cur_check_state = 2;
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //从工程中获取保存的model数据
- //console.log(model.acax_app.model.project.GetModel().pro_model);
- if(model.acax_app.model.project.GetModel().pro_model){
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
-
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- ui.tree_Model.column = [1, tree_color];
- }
- );
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- unit.form.mainfrm.SetColor(difference);
- });
- }
-
- CheckCtrlProcess();
- console.log(model.global_ctrl);
- }
- //切换工况
- function ChangeWorkCondition(wor_name) {
- let tree_color = [];
- var old_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current());
- model.acax_app.control.workCondition.SwitchTo(wor_name);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }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())) {
- cur_check_state = 2;
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //从工程中获取保存的model数据
- if(model.acax_app.model.project.GetModel().pro_model){
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
-
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
-
- ui.tree_Model.column = [1, tree_color];
- CheckCtrlProcess();
- // console.log(model.global_ctrl);
- return old_data;
- }
- //创建工作区
- function CreateWorkArea(name) {
- let tree_color = [];
- console.log("1111");
- HideWorkcondition();
- console.log("2222");
- model.acax_app.control.workArea.Append(name);
- let cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
- if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
- cur_check_state = 2;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- tree_color.push("");
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if("workArea" === info.name) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
- },
- tree=>{
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- });
- ui.tree_Model.position = cur_id;
- //渲染3d模型
- unit.form.mainfrm.ClearCanvas();
- ui.tree_Model.column = [1, tree_color];
- CheckCtrlProcess();
- }
- //创建工程
- function CreateProject(name) {
-
- let tree_color = [];
- //隐藏掉旧的工况
- HideWorkcondition();
- model.acax_app.control.project.Create(name);
- let cur_name = model.acax_app.model.project.Current();
- let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
- if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
- cur_check_state = 2;
- }
-
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- tree_color.push("");
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
-
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree=>{
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- });
- ui.tree_Model.position = cur_id;
- //渲染3d模型
- if(model.acax_app.model.project.GetModel().step === "unimported") {
- unit.form.mainfrm.ClearCanvas();
- }
- ui.tree_Model.column = [1, tree_color];
- CheckCtrlProcess();
- }
- //导入模型
- function OnOpenStepFile() {
- if(model.global_ctrl[0] && model.global_ctrl[1] ) {
- var model_file = myArray[parseFloat(ui.listbox.index)];
- model.acax_app.control.ImportStep(model_file, (model_file, model_plyfile)=>{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- );
-
- }else{
- unit.form.mainfrm.OnCueline('未创建工程', 'red');
- return;
- }
-
- }
- //插入新子节点
- function findAndAppendByName(json, targetName, newChild) {
- if (json.name === targetName) {
- // 拼接新的 JSON 数据
- if (!json.children) {
- json.children = [];
- }
- json.children.unshift(newChild);
- return true; // 找到后返回 true
- }
- // 遍历子节点递归查找
- if (json.children) {
- for (const child of json.children) {
- if (findAndAppendByName(child, targetName, newChild)) {
- return true; // 如果找到目标节点,结束递归
- }
- }
- }
- return false; // 没找到返回 false
- }
- //给面节点改名字并添加check_state属性
- function updateJsonNodes(jsonData) {
- let count = 1; // 用于计数生成 Face1, Face2...
- //let count_id = 100000;
- function traverse(node) {
- // 为每个节点添加 check_state: 2 属性
- node.check_state = 3;
- node.icon = '';
- node.r_id = node.id;
- node.id = node.faceId;
- //node.id = ++count_id;
- if(node.id === 100001) {
- node.icon = 'model2';
- }else if(node.id === 100002) {
- node.icon = 'model3';
- }
- // 如果存在 children 属性,则递归处理
- if (node.children && Array.isArray(node.children)) {
- for (let child of node.children) {
- traverse(child); // 递归遍历子节点
- }
- } else if (node.name && node.name.startsWith("Face_")) {
- // 修改 name 值为 Face1, Face2...
- node.name = `Face${count}`;
- node.icon = 'face';
- count++;
- }
- }
- traverse(jsonData);
- return jsonData;
- }
- //查找模型的第一个节点值获取id
- function getFirstId(obj) {
- // 检查是否有 children 并提取第一个节点的 id
- if (obj.children && obj.children.length > 0) {
- return obj.children[0].id;
- }
- return null; // 如果没有子节点,返回 null
- }
- // 深度优先遍历函数
- function getTreeColorsInOrder(tree) {
- // 定义存储颜色的数组
- const tree_color = [];
- // 定义递归函数
- function dfs(node) {
- // 如果当前节点有 color 属性,则加入数组
- if (node.color !== undefined) {
- tree_color.push(node.color);
- }
- // 按顺序遍历子节点
- if (node.children && node.children.length > 0) {
- node.children.forEach(child => dfs(child));
- }
- }
- // 调用递归函数,传入根节点
- dfs(tree);
- // 返回颜色数组
- return tree_color;
- }
- //将模型颜色存成map
- function getTreeIdColorMap(tree) {
- // 定义存储 id 和 color 的对象
- const idColorMap = {};
- // 定义递归函数
- function dfs(node) {
- // 检查当前节点的 name 属性是否包含 "face",以及是否具有 id 和 color 属性
- if (node.name && node.name.includes("Face") && node.id !== undefined && node.color !== undefined) {
- idColorMap[node.id] = node.color;
- }
- // 如果存在子节点,递归遍历
- if (node.children && node.children.length > 0) {
- node.children.forEach(child => dfs(child));
- }
- }
- // 调用递归函数,传入根节点
- dfs(tree);
- // 返回存储的 id 和 color 键值对对象
- return idColorMap;
- }
- //获取模型面的颜色保存到project
- function SetModelColor(Idx) {
- let model_color = getTreeIdColorMap(Idx);
- let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
- let model_prop = model.acax_app.view.GetProperty(cut_project_index);
- if(model_prop === undefined) {
- model_prop = {};
- model_prop.color = model_color;
- model.acax_app.view.SetProperty(cut_project_index, model_prop);
- }else{
- model_prop.color = model_color;
- model.acax_app.view.SetProperty(cut_project_index, model_prop);
- }
- //console.log(model.acax_app.view.GetProperty(cut_project_index));
- }
- //将颜色给模型赋回去
- function assignColorsToTree(tree, idColorMap) {
- // 定义递归函数
- function dfs(node) {
- // 如果当前节点的 id 存在于 idColorMap 中,赋值回 color
- if (node.id !== undefined && idColorMap[node.id] !== undefined) {
- node.color = idColorMap[node.id];
- }
- // 按顺序遍历子节点
- if (node.children && node.children.length > 0) {
- node.children.forEach(child => dfs(child));
- }
- }
- // 调用递归函数,传入根节点
- dfs(tree);
- // 返回更新后的树
- return tree;
- }
- //找记录颜色和生成颜色不同的键值对
- function findDifferences(oldMap, newMap) {
- const differences = {};
- for (const key in oldMap) {
- if (oldMap[key] !== newMap[key]) {
- differences[key] = newMap[key];
- }
- }
- return differences;
- }
- var difference = {};
- //获取工程中颜色,为模型涂色
- function SetUserColor() {
- var dif_key = Object.keys(difference);
- console.log(dif_key.length);
- for(let i = 0;i < dif_key.length;++i) {
- let rgb = hexToRgb(difference[dif_key[i]]);
- try {
- unit.form.mainfrm.LightFace(dif_key[i], rgb); // 调用设置颜色
- } catch (error) {
- console.error(`Failed to apply color for key ${dif_key[i]}`, error);
- }
-
- }
- }
- //导入模型树节点
- function OnTree(Idx){
-
- let tree_color = [];
- //console.log(JSON.stringify(Idx, null, 2));
- updateJsonNodes(Idx);
-
- //模型树颜色
- let cut_project_index = model.acax_app.view.GetCurrentProjectIndex();
- if(model.acax_app.view.GetProperty(cut_project_index) !== undefined ) {
- //获取工程中的模型颜色,为树赋颜色
- if(model.acax_app.view.GetProperty(cut_project_index).color!==undefined ) {
- var old_map = getTreeIdColorMap(Idx);
- //console.log(old_map);
- //console.log(model.acax_app.view.GetProperty(cut_project_index).color);
- difference = findDifferences(old_map, model.acax_app.view.GetProperty(cut_project_index).color);
- //console.log(difference);
- assignColorsToTree(Idx, model.acax_app.view.GetProperty(cut_project_index).color);
- }
-
- }else{
- SetModelColor(Idx);
- }
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- //设置id
- let color = "";
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
- if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
- cur_check_state = 2;
- }
-
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
-
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //从工程中获取保存的model数据
- //插入模型树节点与工程节点进行拼接
- let pro_Index= model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- findAndAppendByName(tree, pro_name, Idx);
- //将模型树节点与工程节点拼接后保存到model中
- let pro_model = model.acax_app.model.project.GetModel();
- pro_model.pro_model = Idx;
- model.acax_app.model.project.SetModel(pro_model);
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.column = [1, tree_color];
- ui.tree_Model.position = getFirstId(Idx);
- //表示模型已导入
- model.global_ctrl[2] = true;
- }
- //创建工况
- function CreateWorkCondition(name){
- let tree_color = [];
- //隐藏掉旧的工况
- HideWorkcondition();
-
- let condition_index = model.acax_app.control.workCondition.Create(name);
- let cur_name = model.acax_app.model.workCondition.Current();
- let cur_index = model.acax_app.view.GetCurrentProjectIndex();
- let cur_id;
- //console.log(model.acax_app.path.Parent(cur_index, 2) === model.acax_app.view.GetCurrentProjectIndex());
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }
- if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) {
- cur_check_state = 2;
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 2) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- //模型存在在加载
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
-
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
-
- ui.tree_Model.position = cur_id;
- ui.tree_Model.column = [1, tree_color];
- }
- //创建材料属性
- function CreateMaterial(mat) {
- let tree_color = [];
- model.acax_app.control.materialProp.Create(mat);
- let cur_name = model.acax_app.model.materialProp.Current();
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }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())) {
- cur_check_state = 2;
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
-
- //将材料属性添加到模型信息中
- model.acax_app.view.Render3D(info=>{
- console.log(info.materialProps);
- info.materialProps.push(mat);
- console.log("2222222");
- });
- ui.tree_Model.position = cur_id;
- ui.tree_Model.column = [1, tree_color];
- model.global_ctrl[5] = true;
- }
- //修改材料面板属性属性
- function ModifyMaterial(material) {
- //获取当前材料的名字
- let material_name = model.acax_app.model.materialProp.Current();
- model.acax_app.control.materialProp.Set(material, material_name);
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }
- //创建载荷
- function CreateBoundary(Load, name) {
- console.log(model.global_ctrl);
- if(!model.global_ctrl[0] || !model.global_ctrl[1] || !model.global_ctrl[2] || !model.global_ctrl[3]) {
- unit.form.mainfrm.OnCueline('未满足创建条件', 'red');
- return;
- }
- let tree_color = [];
-
- let load = model.acax_app.control.constrain.Create(Load, name);
-
- let cur_name = model.acax_app.model.constrain.Current();
-
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- var cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- let icon = "";
- let color = "";
- //设置id
- let cur_check_state = 0;
- let cur_type = model.acax_app.path.Type(info.index);
-
- if( cur_type === 0 || cur_type === 2 || cur_type === 5) {
- cur_check_state = 3;
- }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())) {
- cur_check_state = 2;
- }
- let id2index = g_cur_id2index_cache;
- let index2id = g_cur_index2id_cache;
-
- let index = info.index;
- let id = info.id;
- //赋予图标
- if(CheckPicture(cur_type)){
- icon = CheckPicture(cur_type);
- }
-
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
-
- cur_id = info.id;
- cur_check_state = 2;
- }
- if(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "#bbbbbb";
- }
- //获取约束颜色
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- //将第一个节点设为无选择框
- if(info.id === 1) {
- cur_check_state = 3;
- icon = "form";
- }
- return {
- name : info.name,
- icon : icon,
- id : info.id,
- check_state : cur_check_state,
- color : color
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
- //赋值给dcip的树结构
- tree_color = getTreeColorsInOrder(tree);
- ui.tree_Model.tree = tree;
- }
- );
- //将载荷属性添加到模型信息中
- ui.tree_Model.position = cur_id;
- //console.log(tree_color);
- ui.tree_Model.column = [1, tree_color];
- model.acax_app.view.Render3D(info=>{
- info.constrains.push(Load);
-
- });
-
- }
- //修改载荷面板属性
- function ModifyConstraint(constrain) {
- let constrain_name = model.acax_app.model.constrain.Current();
- model.acax_app.control.constrain.Set(constrain, constrain_name);
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }
- function OnMessage(idx){
- ui.cueline.value += idx + '\n';
- ui.cueline.row = -1;
- }
- function OnChangeMenu(Idx){
- ui.tree_menu.index = parseInt(Idx);
- }
- function OnDeleteFile() {
- myArray.splice(parseFloat(ui.listbox.index), 1);
- ui.listbox.list = [
- myArray
- ];
- }
- function OnOpenFile(){
- var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Step Files(*.step *.stp);;Iges Files(*.iges *.igs);;Nastran Files(*.nas)");
- model.write(fname, model.getCurrentDirectory() + '/data/address.txt');
- myArray.push(fname);
- ui.listbox.list = [
- myArray
- ];
- }
- function OnChangeOptions(){
- options = !options;
- ui.stack_options.visible = options;
-
- }
- function OnTopMenu(idx) {
- ui.stack_import.visible = true;
- ui.stack_import.index = parseInt(idx) - 1;
- ui.pb_import01.valid = ui.pb_import02.valid = ui.pb_import03.valid = ui.pb_import04.valid = ui.pb_import05.valid = false;
- //model.ide_info(idx);
- if (parseInt(idx) === 1) {
- ui.pb_import01.valid = true;
- }
- if (parseInt(idx) === 2) {
- ui.pb_import02.valid = true;
- }
- if (parseInt(idx) === 3) {
- ui.pb_import03.valid = true;
- }
- if (parseInt(idx) === 4) {
- ui.pb_import04.valid = true;
- }
- if (parseInt(idx) === 5) {
- ui.pb_import05.valid = true;
- }
- }
- //The message corresponding callback executed by the docker pane.
- // when calling [side_pane].fireEvent(type,para) in the main form.
- function OnParentDockerMessage(type, para) {
- }
- //////////////////////////////////////////////////////////////////////////
- // Utils Functions.
- // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
- function onDragFile(filepath) {
- }
- function PUI(cb) {
- if(pui){cb();}
- }
- /*Usage of BLOCK_EVENT
- BLOCK_EVENT(()=>{
- ui.[name].[var] = ...;
- });
- */
- function BLOCK_EVENT(cb) {
- ui.block_event = true;
-
- cb();
-
- ui.block_event = false;
- }
- //////////////////////////////////////////////////////////////////////////
- // template codes for cw callback js.
- function CW_DeclareVariable(name, setter, getter) {
- if(typeof(__DeclareVariable) === 'function') {
- __DeclareVariable(name, setter, getter);
- }
- }
- function CW_DeclareOuterVariable(name) {
- if(typeof(__DeclareOuterVariable) === 'function') {
- __DeclareOuterVariable(name);
- }
- }
|