cs.cpp
来自「FreeFem++可以生成高质量的有限元网格。可以用于流体力学」· C++ 代码 · 共 804 行 · 第 1/2 页
CPP
804 行
// See errors more easily in debug mode#ifdef BIG_SYNTAX_ERRORS {FL_RED,FL_COURIER_BOLD,20} // I=errors#else {FL_RED,FL_COURIER_BOLD,FL_NORMAL_SIZE} // I=errors#endif};// Called by Fl::add_timeout() to read the first file only after// Fl::run() is called (otherwise FLTK crashes on Win32)string firstfile;void readfirstfile(void*){ readfile(firstfile); Fl::remove_timeout(readfirstfile);}// Main client programint clientmain(int argc,char *argv[]){ try{ // Starts threads protection in FLTK Fl::lock(); // Path to server program // ---------------------- // Records the command used to start the client, as a first guess as // how to start the server. commandline=string(argv[0]); // Adds the full path (we are going to change directories). if( // Not if the path starts with a slash commandline[0]!='/' && commandline[0]!='\\' // Neither if the path starts with a drive letter && !(commandline.size()>=3 && commandline[1]==':' && commandline[2]=='\\') // If there is no slash in the command, it has been run through a // PATH and no directory should be added (todo: this is not quite // true if PATH contains "."). && (commandline.rfind('/',commandline.size())!=string::npos || commandline.rfind('\\',commandline.size())!=string::npos)){ char dir[1024]; if(getcwd(dir,1024)==NULL) throw string("Could not get current working directory"); commandline=string(dir)+'/'+commandline; } // If client and server are not in the same executable, we need to // find the server!#ifndef CLIENTSERVER // Change client name into server name string dir,base; splitpath(commandline,dir,base); if(dir!="") commandline=dir+"FreeFem++-server"; else commandline="FreeFem++-server";#endif // CLIENTSERVER // Replace dialog // -------------- replacedialog=new Fl_Window(300,105,"Replace"); replacedialogfind=new Fl_Input(80,10,210,25,"Find:"); replacedialogfind->align(FL_ALIGN_LEFT); replacedialogwith=new Fl_Input(80,40,210,25,"Replace:"); replacedialogwith->align(FL_ALIGN_LEFT); replacedialogall=new Fl_Button(10,70,90,25,"Replace All"); replacedialogall->callback((Fl_Callback*)replaceall); replacedialognext=new Fl_Return_Button(105,70,120,25,"Replace Next"); replacedialognext->callback((Fl_Callback*)replaceagain); replacedialogcancel=new Fl_Button(230,70,60,25,"Cancel"); replacedialogcancel->callback((Fl_Callback*)replacecancel); replacedialog->end(); replacedialog->set_non_modal(); // Main window proportions // ----------------------- const int mainwindowwidth=800; const int mainwindowheight=600; const int buttonwidth=70; const int buttonheight=25; const int menubarheight=buttonheight; const int toolbarheight=buttonheight; const int messagebarheight=25; const int outputheight=150; const int buttonspacing=buttonwidth; const int workingareatop=menubarheight; const int workingareaheight=mainwindowheight -menubarheight -messagebarheight; const int workingareabottom=workingareatop+workingareaheight; const int editorareaheight=workingareaheight-outputheight; const int editorareawidth=mainwindowwidth/2; mainwindow=new Fl_Double_Window(mainwindowwidth,mainwindowheight); mainwindow->callback(quit); // Icons // -----#ifdef WIN32 // Mingw32 or Cygwin mainwindow->icon((char*)LoadIcon(fl_display,MAKEINTRESOURCE(LOGO2)));#endif#if defined(__linux__) fl_open_display(); Pixmap p,mask; XpmCreatePixmapFromData(fl_display,DefaultRootWindow(fl_display), gui_logo2_xpm,&p,&mask,NULL); mainwindow->icon((char*)p);#endif // Main menu // --------- Fl_Menu_Item menuitems[]={ {"&File",0,0,0,FL_SUBMENU}, {"&New File",0,(Fl_Callback*)newfile}, {"&Open File...",FL_CTRL+'o',(Fl_Callback*)openfile}, {"&Save File",FL_CTRL+'s',(Fl_Callback*)savefile}, {"Save File &As...",0,(Fl_Callback*)savefileas,0,FL_MENU_DIVIDER}, // todo: enable dynamic greying out //{"Run FreeFem++",0,(Fl_Callback*)startfreefemserver}, //{"Pause FreeFem++",0,(Fl_Callback*)pausefreefemserver}, //{"Stop FreeFem++",0,(Fl_Callback*)stopfreefemserver,0,FL_MENU_DIVIDER}, {"E&xit",FL_CTRL+'q',(Fl_Callback*)quit,0}, {0}, {"&Edit",0,0,0,FL_SUBMENU}, {"Cu&t",FL_CTRL+'x',(Fl_Callback*)cut}, {"&Copy",FL_CTRL+'c',(Fl_Callback*)copy}, {"&Paste",FL_CTRL+'v',(Fl_Callback*)paste}, {"&Delete",0,(Fl_Callback*)deletetext}, {0}, {"&Search",0,0,0,FL_SUBMENU}, {"&Find...",FL_CTRL+'f',(Fl_Callback*)find}, {"F&ind Again",FL_CTRL+'g',findagain}, {"&Replace...",FL_CTRL+'r',replace}, {"Re&place Again",FL_CTRL+'t',replaceagain}, {0}, {0} }; Fl_Menu_Bar menubar(0,0,mainwindowwidth,menubarheight); menubar.copy(menuitems); // Working area, made of several separate zones // -------------------------------------------- Fl_Tile workingarea(0,workingareatop,mainwindowwidth,workingareaheight); // Editor area Fl_Group editorarea(0,workingareatop, editorareawidth,editorareaheight); // editor toolbar Fl_Group editortoolbar(0,workingareatop, editorareawidth,workingareatop+toolbarheight); editortoolbar.box(FL_FLAT_BOX); // run int buttonx=0; runbutton=new Fl_Button(buttonx,workingareatop,buttonwidth,toolbarheight, "Run"); runbutton->callback(startfreefemserver); runbutton->tooltip("Run FreeFem++ on the program displayed in the editor"); // pause. buttonx+=buttonspacing; pausebutton=new Fl_Button(buttonx,workingareatop,buttonwidth,toolbarheight, "Pause"); pausebutton->callback(pausefreefemserver); pausebutton->type(FL_TOGGLE_BUTTON); pausebutton->tooltip("Temporarily pause a running FreeFem++ computation" " (press again to resume)"); pausebutton->deactivate(); // stop buttonx+=buttonspacing; stopbutton=new Fl_Button(buttonx,workingareatop,buttonwidth,toolbarheight, "Stop"); stopbutton->callback(stopfreefemserver); stopbutton->tooltip("Kill any currently running FreeFem++ computation"); stopbutton->deactivate(); editortoolbar.resizable(NULL); editortoolbar.end(); // editor window editorbuffer=new Fl_Text_Buffer; highlightbuffer=new Fl_Text_Buffer(editorbuffer->length()); inithighlight(); editor=new Editor(0,workingareatop+toolbarheight, editorareawidth,editorareaheight-toolbarheight); editor->buffer(editorbuffer); editorbuffer->add_modify_callback(textchanged,NULL); editor->textfont(FL_COURIER); editor->highlight_data(highlightbuffer,styletable, sizeof(styletable)/sizeof(styletable[0]), highlight_plain,unfinishedhighlight,0); editorbuffer->add_modify_callback(updatehighlight,NULL); editorbuffer->call_modify_callbacks(); editorarea.resizable(editor); editorarea.end(); // graphics area graphicsarea=new Fl_Group(editorareawidth, workingareatop, mainwindowwidth-editorareawidth, editorareaheight); // graphics toolbar graphicstoolbar=new Fl_Group(editorareawidth, workingareatop, mainwindowwidth-editorareawidth, toolbarheight); graphicstoolbar->box(FL_FLAT_BOX); // Create a group for all mouse control options fl_font(FL_HELVETICA,17); const char *clickmeanslabel="Click means:"; const int clickmeanslabelsize=static_cast<int>(fl_width(clickmeanslabel)); const char *clickpauselabel="Continue"; const int clickpauselabelsize= static_cast<int>(fl_width(clickpauselabel))+10; buttonx=editorareawidth; Fl_Group clickcontrolarea(buttonx,workingareatop, clickmeanslabelsize+clickpauselabelsize +3*buttonwidth,toolbarheight); Fl_Output clickmeans(buttonx,workingareatop, clickmeanslabelsize,toolbarheight); clickmeans.value(clickmeanslabel); clickmeans.box(FL_FLAT_BOX); clickmeans.color(FL_GRAY); // Click on the picture to un-pause (like previous FreeFem++ versions) buttonx+=clickmeanslabelsize; clickpausebutton=new Fl_Round_Button(buttonx,workingareatop, clickpauselabelsize, toolbarheight,clickpauselabel); clickpausebutton->type(FL_RADIO_BUTTON); clickpausebutton->tooltip("If this is set," " clicking in the graphics window will resume " "a paused FreeFem++ computation"); // Zooming in or out buttonx+=clickpauselabelsize; Fl_Round_Button zoominbutton(buttonx,workingareatop, buttonwidth,toolbarheight,"Zoom +"); zoominbutton.type(FL_RADIO_BUTTON); zoominbutton.callback(zoomin); zoominbutton.tooltip("If this is set," " left-clicking in the graphics window " "will make it bigger"); buttonx+=buttonspacing; Fl_Round_Button zoomoutbutton(buttonx,workingareatop, buttonwidth,toolbarheight,"Zoom -"); zoomoutbutton.type(FL_RADIO_BUTTON); zoomoutbutton.callback(zoomout); zoomoutbutton.tooltip("If this is set," " left-clicking in the graphics window " "will make it smaller"); clickpausebutton->setonly(); clickcontrolarea.end(); buttonx+=buttonspacing; Fl_Button zoomresetbutton(buttonx,workingareatop, buttonwidth,toolbarheight,"No Zoom"); zoomresetbutton.callback(zoomreset); zoomresetbutton.tooltip("Forget any zooming coefficient" " and redraw the image"); // This toolbar will only be activated when something is drawn graphicstoolbar->resizable(NULL); graphicstoolbar->deactivate(); graphicstoolbar->end(); // graphics window graphics=new Tffgraphics(editorareawidth, workingareatop+toolbarheight, mainwindowwidth-editorareawidth, editorareaheight-toolbarheight); graphicsarea->resizable(graphics); graphicsarea->end(); // FreeFem++ output output=new Fl_Text_Display(0,workingareatop+editorareaheight, mainwindowwidth,outputheight); outputbuffer=new Fl_Text_Buffer; output->buffer(outputbuffer); output->color(FL_WHITE); workingarea.end(); mainwindow->resizable(workingarea); // Status bar // ---------- messagebar=new Fl_Output(0,workingareatop+workingareaheight, mainwindowwidth,messagebarheight); messagebar->color(FL_GRAY); messagebar->value("Ready"); // Final initialisations // --------------------- mainwindow->end(); Fl::visual(FL_DOUBLE|FL_INDEX); setwindowtitle();#ifdef CLIENTSERVER output->insert("\n-- FreeFem++ IDE client+server v");#else output->insert("\n-- FreeFem++ IDE client v");#endif output->insert(StrVersionNumber().c_str()); output->insert("\n"); output->show_insert_position(); mainwindow->show(); editor->take_focus(); // Command-line parameters // ----------------------- // A file name can be specified on the command line. int filearg=1; // MacOS adds an argument starting with "-psn" ("process serial // number"), which we do not use here. if(argc>=2 && strncmp(argv[1],"-psn",4)==0) filearg+=1; if(argc==filearg+1){ // If we read the file now, it will activate the highlighting // procedure, which will call Fl::lock() before Fl::run(). This // crashes FLTK on Win32. So we wait until Fl::run() is called // by asking Fl::wait() to load the file. firstfile=argv[filearg]; // A 1 second delay is enough on a dual-proc PIII 800Mhz // ("ljlldevelop"). TODO: Would this be enough on any Windows // machine? Fl::add_timeout(1.0,readfirstfile); }#ifndef NDEBUG else if(argc!=filearg){ fl_alert("FreeFem++: Wrong number of command-line arguments"); }#endif // Main loop // --------- return Fl::run(); } catch(string explanation){ // Use cerr because the graphical environment may not be properly // initialized at the time of the error. cerr<<"client: "<<explanation<<endl; }}#endif // CLIENT// Main program// ------------int main(int argc,char *argv[]){ // Client/Server mechanism // -----------------------#ifdef CLIENTSERVER if(argc>=2 && string(argv[1])=="server") return servermain(argc,argv); else return clientmain(argc,argv);#else#ifdef CLIENT return clientmain(argc,argv);#endif#ifdef SERVER return servermain(argc,argv);#endif#endif // CLIENTSERVER}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?