/* * File: hello.cc * Purpose: Demo for wxWindows class library * Author: Julian Smart * Created: 1993 * Updated: * Copyright: (c) 1993, AIAI, University of Edinburgh */ static const char sccsid[] = "%W% %G%"; #ifdef __GNUG__ #pragma implementation #endif #ifdef wx_msw #ifndef WIN32 #pragma hdrfile "c:\wx\src\msw\wx.sym" #endif #endif #include "wx.h" #ifdef wx_msw #pragma hdrstop #endif #include #include "wx_timer.h" #include "wx_mf.h" #include "ansys2dx.h" #if defined(wx_msw) && !defined(__WATCOMC__) #include "mmsystem.h" #endif // Declare two frames MyFrame *frame = NULL; wxMenuBar *menu_bar = NULL; Bool timer_on = FALSE; wxBitmap *test_bitmap = NULL; wxIcon *test_icon = NULL; wxMenu *the_file_menu ; // This statement initialises the whole application MyApp myApp; // For drawing lines in a canvas float xpos = -1; float ypos = -1; #ifdef wx_x #include "aiai.xbm" #include "fload.xbm" #endif #define BUTTON_TAG 1 #define PIXMAP_TAG 2 class Node : public wxObject { public: Node(long id, long nid, float x, float y, float z) : wxObject() { fid = id; fnid = nid; fx = x; fy = y; fz = z; used = 0; } int used; float fx, fy, fz; long fid; long fnid; }; // A macro needed for some compilers (AIX) that need 'main' to be defined // in the application itself. IMPLEMENT_WXWIN_MAIN // Testing of ressources MyApp::MyApp() { } // The `main program' equivalent, creating the windows and returning the // main frame wxFrame *MyApp::OnInit(void) { #if defined(wx_msw) && !defined(__WATCOMC__) mciSendString("play welcome.wav", wxBuffer, 1000, 0); #endif // Create the main frame window frame = new MyFrame(NULL, "CENAPAD-SP - Conversor ANSYS -> DX", 0, 0, 550, 650); // Give it a status line frame->CreateStatusLine(2); // Load icon and bitmap #ifdef wx_msw test_icon = new wxIcon("aiai_icn"); test_bitmap = new wxBitmap("fload") ; #endif #ifdef wx_x test_icon = new wxIcon(aiai_bits, aiai_width, aiai_height); test_bitmap = new wxBitmap(fload_bits,fload_width,fload_height) ; #endif frame->SetIcon(test_icon); // Make a menubar wxMenu *file_menu = new wxMenu; the_file_menu = file_menu ; file_menu->AppendSeparator(); file_menu->Append(HELLO_QUIT, "&Sair", "Finaliza"); wxMenu *help_menu = new wxMenu; help_menu->Append(HELLO_ABOUT, "&Sobre...", "Sobre o ansys2dx"); menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&Arquivo"); menu_bar->Append(help_menu, "&Help"); // Associate the menu bar with the frame frame->SetMenuBar(menu_bar); // Make a panel // frame->panel = new wxPanel(frame, 0, 0, 550, 500, 0, "MyMainFrame"); frame->panel = new wxPanel(frame, 0, 0, 1000, 650, 0, "MyMainFrame"); frame->panel->SetLabelPosition(wxVERTICAL); // A wxText that processes the ENTER key (this _may_ foul up tab traversal) frame->nodef = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo de Nos", "NLIST.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[0] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->elemf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo de Elementos", "ELIST.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[1] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->cbdata = new wxCheckBox(frame->panel, NULL , ""); frame->cbdata->SetValue(TRUE); frame->dataf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo das Tensoes Principais", "PRNSOL.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[2] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->cbscomp = new wxCheckBox(frame->panel, NULL , ""); frame->cbscomp->SetValue(TRUE); frame->scompf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo das Tensoes", "PRNSOL1.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[3] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->cbecomp = new wxCheckBox(frame->panel, NULL , ""); frame->cbecomp->SetValue(TRUE); frame->ecompf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo das Deformacoes", "PRNSOL2.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[4] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->cbvecu = new wxCheckBox(frame->panel, NULL , ""); frame->cbvecu->SetValue(TRUE); frame->vecuf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo dos Deslocamentos (U)", "PRNSOL2.lis", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[5] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); frame->dxf = new wxText(frame->panel, (wxFunction)&text_proc, "Arquivo DX", "ansys2dx.dx", 50, -1, 350, -1, wxPROCESS_ENTER) ; frame->btf[6] = new wxButton(frame->panel, (wxFunction)&find_proc, "Procurar...") ; frame->panel->NewLine(); char *radio_strings[2]; radio_strings[0] = "4"; radio_strings[1] = "8"; frame->rb = new wxRadioBox(frame->panel,NULL,"No. de nos por elemento",-1,-1,-1,-1, 2,radio_strings,2,wxHORIZONTAL|wxFLAT); frame->panel->NewLine(); frame->panel->NewLine(); new wxButton(frame->panel, (wxFunction)&button_proc, " Ok ", 100) ; new wxButton(frame->panel, (wxFunction)&quit_proc, "Cancela", 200) ; frame->Show(TRUE); // Return the main frame window return frame; } // Define my frame constructor MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): wxFrame(frame, title, x, y, w, h) { panel = NULL; for(int i = 0; i<6; i++) btf[i] = NULL; } MyFrame::~MyFrame(void) { for(wxNode *n = Nodes.First(); n; n = Nodes.First()) { Node *node = (Node *)n->Data(); delete node; delete n; } for(wxNode *n = uNodes.First(); n; n = uNodes.First()) { Node *node = (Node *)n->Data(); delete node; delete n; } } // Intercept menu commands void MyFrame::OnMenuCommand(int id) { switch (id) { case HELLO_QUIT: { OnClose(); delete this; break; } case HELLO_ABOUT: { (void)wxMessageBox("ansys2dx Conversor de dados gerados pelo ANSYS para o formato Data Explorer\nAutor: Erico C. da Silva erico@cenapad.unicamp.br\nCENAPAD-SP (c) 1996", "Sobre o ansys2dx", wxOK|wxCENTRE); break; } } } // Size the subwindows when the frame is resized void MyFrame::OnSize(int w, int h) { if (panel) { int width, height; GetClientSize(&width, &height); // panel->SetSize(0, 0, width, (int)(height/*/2*/)); // text_window->SetSize(0, (int)(height/2), width, (int)(height/2)); } } // Define the behaviour for the frame closing // - must delete all frames except for the main one. Bool MyFrame::OnClose(void) { Show(FALSE); return TRUE; } void MyFrame::SetArcName(wxButton *but, char *file) { int i; for(i = 0; i < 6; i++) if((btf[i])==but) break; switch(i) { case 0: nodef->SetValue(file); break; case 1: elemf->SetValue(file); break; case 2: dataf->SetValue(file); break; case 3: scompf->SetValue(file); break; case 4: ecompf->SetValue(file); break; case 5: vecuf->SetValue(file); break; case 6: dxf->SetValue(file); break; } return; } void MyFrame::DoConversion(void) { wxCursor *ocursor = panel->SetCursor(wxHOURGLASS_CURSOR); ::wxSetCursor(wxHOURGLASS_CURSOR); long nn = CnvNodes(); long ne = CnvElems(); long nnw = WriteNodes(); long nd = CnvData(nn); long nscomp = CnvSComp(nn); long necomp = CnvEComp(); long nvu = CnvVecU(); if(nn > nnw) { ne = CnvElems(); } else if(nn < nnw) { cout << "erro : nn < nnw"; exit(1); } filebuf ofb; char *fn = dxf->GetValue(); ofb.open(fn, ios::out); ostream ofile(&ofb); ofile << "object 1 class array type float rank 1 shape 3 items " << nnw << " data file " << fnname <<", 0"<< endl; ofile << "attribute \"dep\" string \"positions\"" << endl; ofile << "#" << endl; ofile << "object 2 class array type int rank 1 shape "<< ((rb->GetSelection())? 8 : 4) <<" items " << ne << " data file " << felname <<", 0"<GetSelection())? "\"cubes\"" : "\"quads\"") << endl; ofile << "attribute \"ref\" string \"positions\"" << endl; ofile << "#" << endl; if(nd) { ofile << "object 3 class array type float rank 1 shape 5 items " << nd << " data file " << fdname <<", 0"<SetCursor(ocursor); } long MyFrame::CnvElems() { filebuf ifb; filebuf ofb; int nn = (rb->GetSelection())? 8 : 4; char fname[255]; char *fn = elemf->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(felname, fname); ofb.open(fname, ios::out); istream ifile(&ifb); ostream ofile(&ofb); char stuff[255]; char *hdr = " ELEM MAT TYP REL ESY NODES"; long te = 0L; while(!ifile.eof()) { long int n[10]; int ne, mat, tp, r, e; do ifile.getline(stuff, 255, '\n'); while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; ifile.getline(stuff, 255, '\n'); while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> ne >> mat >> tp >> r >> e; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } te++; for(int s = 0; s < nn; s++) { int tn; ifile >> tn; Node *node = (Node *)(Nodes.Find(tn))->Data(); if(node) { n[s] = node->fnid; for(wxNode *unode = uNodes.First(); unode; unode = unode->Next()) { Node *cn = ((Node *)unode->Data()); if(node->fnid > cn->fnid) n[s]--; } node->used = 1; } else { cout << "referencia a um no inexistente"; exit(1); } } // if(nn==8) // { int tmp = n[1]; n[1] = n[0]; n[0] = tmp; if(nn==8) { tmp = n[5]; n[5] = n[4]; n[4] = tmp; } for(int s = 0; s < nn; s++) { ofile << n[s] <<" "; } ofile << endl; } } ifb.close(); ofb.close(); return te; } long MyFrame::CnvData(long /*nf*/) { if(!cbdata->GetValue()) return 0L; filebuf ifb; filebuf ofb; char fname[255]; char *fn = dataf->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(fdname, fname); ofb.open(fname, ios::out); istream ifile(&ifb); ostream ofile(&ofb); char stuff[255]; char *hdr = " NODE S1 S2 S3 SINT SEQV "; long te = 0L; while(!ifile.eof()) { int nn; double s1, s2, s3, sint, seqv; do { ifile.getline(stuff, 255, '\n'); }while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> nn >> s1 >> s2 >> s3 >> sint >> seqv; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } te++; ofile << s1 <<" "<< s2 <<" "<< s3 <<" "<< sint <<" "<< seqv << endl; } } ifb.close(); ofb.close(); return te; } long MyFrame::CnvSComp(long /*nf*/) { if(!cbscomp->GetValue()) return 0L; filebuf ifb; filebuf ofb; char fname[255]; char *fn = scompf->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(fscname, fname); ofb.open(fname, ios::out); istream ifile(&ifb); ostream ofile(&ofb); char stuff[255]; char *hdr = " NODE SX SY SZ SXY SYZ SXZ"; long te = 0L; while(!ifile.eof()) { int nn; double sx, sy, sz, sxy, syz, sxz; do { ifile.getline(stuff, 255, '\n'); }while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> nn >> sx >> sy >> sz >> sxy >> syz >> sxz; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } te++; ofile << sx <<" "<< sy <<" "<< sz <<" "<< sxy <<" "<< syz <<" "<< sxz << endl; } } ifb.close(); ofb.close(); return te; } long MyFrame::CnvEComp() { if(!cbecomp->GetValue()) return 0L; filebuf ifb; filebuf ofb; char fname[255]; char *fn = ecompf->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(fecname, fname); ofb.open(fname, ios::out); istream ifile(&ifb); ostream ofile(&ofb); char stuff[255]; char *hdr = " NODE EPTOX EPTOY EPTOZ EPTOXY EPTOYZ EPTOXZ"; long te = 0L; while(!ifile.eof()) { int nn; double ex, ey, ez, exy, eyz, exz; do { ifile.getline(stuff, 255, '\n'); }while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> nn >> ex >> ey >> ez >> exy >> eyz >> exz; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } te++; ofile << ex <<" "<< ey <<" "<< ez <<" "<< exy <<" "<< eyz <<" "<< exz << endl; } } ifb.close(); ofb.close(); return te; } long MyFrame::CnvVecU() { if(!cbvecu->GetValue()) return 0L; filebuf ifb; filebuf ofb; char fname[255]; char *fn = vecuf->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(fvuname, fname); ofb.open(fname, ios::out); istream ifile(&ifb); ostream ofile(&ofb); char stuff[255]; char *hdr = " NODE UX UY UZ USUM"; long te = 0L; while(!ifile.eof()) { int nn; double us, ux, uy, uz; do { ifile.getline(stuff, 255, '\n'); }while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> nn >> ux >> uy >> uz >> us; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } te++; ofile << ux <<" "<< uy <<" "<< uz << endl; } } ifb.close(); ofb.close(); return te; } long MyFrame::CnvNodes() { filebuf ifb; filebuf ofb; char fname[255]; char *fn = nodef->GetValue(); strcpy(fname, fn); if(!::wxFileExists(fname)) return 0L; ifb.open(fname, ios::in); char *pptr = strrchr(fname, '.'); if(pptr!=NULL) strcpy(pptr+1,"out"); else strcat(fname,".out"); strcpy(fnname, fname); istream ifile(&ifb); char *hdr = " NODE X Y Z THXY THYZ THZX"; long nrec = 0; char stuff[255]; while(!ifile.eof()) { int nn; double x, y, z, thxy, thyz, thzx; do ifile.getline(stuff, 255, '\n'); while(strncmp(stuff, hdr, strlen(hdr)) && !ifile.eof()); if(ifile.eof()) break; while(!ifile.eof() && !ifile.fail()) { streampos loc = ifile.tellg(); ifile >> nn >> x >> y >> z >> thxy >> thyz >> thzx; if(ifile.fail()) { ifile.seekg(loc); ifile.clear(); break; } if(ifile.eof()) break; Node *np = new Node(nn, nrec, x, y, z); Nodes.Append(nn, np); nrec++; } } ifb.close(); return nrec; } long MyFrame::WriteNodes() { filebuf ofb; ofb.open(fnname, ios::out); long nrec = 0L; ostream ofile(&ofb); for(wxNode *n = Nodes.First(); n; /*n = Nodes.First()*/) { wxNode *on = n; n = on->Next(); Node *node = (Node *)on->Data(); if(node->used) { ofile << node->fx <<" "<< node->fy <<" "<< node->fz << endl; nrec++; } else { delete on; uNodes.Append(node->fid, node); } } ofb.close(); return nrec; } void quit_proc(wxButton& but, wxCommandEvent& event) { ((MyFrame *)((but.GetParent())->GetParent()))->OnMenuCommand(HELLO_QUIT); return; } void find_proc(wxButton& but, wxCommandEvent& event) { MyFrame *win = ((MyFrame *)((but.GetParent())->GetParent())); char *file = wxFileSelector("Relatorio ANSYS", NULL, NULL, NULL, "*.*"); win->SetArcName(&but, file); } // Gets some user input, and sets the status line void text_proc(wxText& but, wxCommandEvent& event) { /* if (event.eventType==wxEVENT_TYPE_TEXT_COMMAND) *(frame->text_window) << "Value changed\n" ; else if (event.eventType==wxEVENT_TYPE_TEXT_ENTER_COMMAND) *(frame->text_window) << "Enter key\n" ; */ } /*// Gets some user input, and sets the status line void check_proc(wxCheckBox& but, wxCommandEvent& event) { btn2->Enable(!but.GetValue()) ; // test of insensitive Pixmap } */ // Gets some user input, and sets the status line void button_proc(wxButton& but, wxCommandEvent& event) { ((MyFrame *)((but.GetParent())->GetParent()))->DoConversion(); return; } /* void GenericOk(wxButton& but, wxCommandEvent& event) { wxDialogBox *dialog = (wxDialogBox *)but.GetParent(); dialog->Show(FALSE); } */