void MainWindow::calculate(int pluginNum) { lockGUI(); if (placesListChanged) { //std::vector<Place*> v_places; std::vector<QListWidgetItem*> items = list.getAllItems(); int size = items.size(); if(size==0) { return; } if(v_places.size()>0) { for(int i = 0; i < (int)v_places.size(); ++i) { delete[] routes[i]; } delete[] routes; } v_places.clear(); for(int i=0; i<size; i++) { QListWidgetItem* item = items.at(i); GeoListItem* geoItem = dynamic_cast<GeoListItem*>(item); v_places.push_back(geoItem->getPlace()); } std::unordered_map<std::pair<Coordinates, Coordinates>, Route, pairhash> unordered_map; routes = new Marble::Route*[size]; for(int i = 0; i < size; ++i) { routes[i] = new Marble::Route[size]; for(int j = 0; j < size; ++j) { Coordinates from = v_places[i]->getCoordinates(); Coordinates to = v_places[j]->getCoordinates(); std::pair<Coordinates, Coordinates> pair = std::make_pair(from, to); std::unordered_map<std::pair<Coordinates, Coordinates>, Route, pairhash>::const_iterator got = m_routesUnorderedMap.find(pair); Route route; // if(got == m_routesUnorderedMap.end()) { route = getRoute(from, to); if(!(from == to) && route.distance() == 0) { writeLog(QString("There is posibility there is no route from position %1 to %2").arg(i).arg(j)); } else { writeLog(QString("Found route from position %1 to %2").arg(i).arg(j)); } } // else // { // route = got->second; // if(!(from == to) && route.distance() == 0) // { // writeLog(QString("There is posibility there is no route from position %1 to %2").arg(i).arg(j)); // } // else // { // writeLog(QString("Already have route from position %1 to %2").arg(i).arg(j)); // } // } routes[i][j] = route; //unordered_map[pair] = route; } } placesListChanged = false; m_routesUnorderedMap.clear(); m_routesUnorderedMap = std::move(unordered_map); } this->m_progBarDial->show(); this->m_progBarDial->setProgress(0); this->m_progBarDial->update(); this->m_progBarDial->repaint(); this->repaint(); KomiwojazerPluginInterface* interface = pluginManager.getPluginByIndex(pluginNum); interface->connectToSLOT(m_progBarDial, SIGNAL(cancelButtonClicked()), true); v_places = interface->calculate(v_places, routes); interface->connectToSLOT(m_progBarDial, SIGNAL(cancelButtonClicked()), true); this->m_progBarDial->hide(); this->m_progBarDial->update(); this->m_progBarDial->repaint(); this->repaint(); setMarkerNumber(); unlockGUI(); }
int radium_main(char *arg){ struct Tracker_Windows *window; #if 0 // Seems to be some kind of problem when running givertcap? Try to uncomment and // see if you can start radium without segfaulting. I can't. -Kjetil. system("/usr/bin/givertcap"); #endif x11_display=XOpenDisplay(NULL); if(x11_display==NULL){ fprintf(stderr, "Unable to open display \"%s\"\n",XDisplayName(NULL)); return 1; } XSetIOErrorHandler (MySysErrorHandler); x11_screen=DefaultScreen(x11_display); printf("arg: -%s-\n",arg); printf("Width/Height: %d/%d\n",DisplayWidth(x11_display,x11_screen),DisplayHeight(x11_display,x11_screen)); X11_init_keyboard(); X11_StartBlockSelector(); X11_StartMidiProperties(); StartGuiThread(); posix_InitPlayer(); if(InitProgram()==true){ /* Here: More inits, receive events, other things. */ bool notend=true; printf("Inited\n"); XFlush(x11_display); // DrawUpTrackerWindow(root->song->tracker_windows); //XFlush(x11_display); window=root->song->tracker_windows; //GFX_StartFileRequester(); X11_StartQtStuff(); BS_UpdateBlockList(); BS_UpdatePlayList(); BS_SelectBlock(root->song->blocks); BS_SelectPlaylistPos(0); if(strlen(arg)>0) Load(arg); lockGUI(); while(notend==true){ int fd; fd_set fdset; XFlush(x11_display); fd=ConnectionNumber(x11_display); FD_ZERO(&fdset); FD_SET(fd,&fdset); unlockGUI(); while((fd=select(fd+1,&fdset,NULL,NULL,NULL)==-1)){ if(errno!=EINTR) break; } lockGUI(); while(XPending(x11_display)) { XEvent event; XNextEvent(x11_display, &event); //XNextEvent (x11_display, &event); window=root->song->tracker_windows; //P2MUpdateSongPosCallBack(); switch(event.type){ case KeyPress: if(X11_KeyPress((XKeyEvent *)&event,window)==1){ notend=false; } break; case KeyRelease: X11_KeyRelease((XKeyEvent *)&event,window); break; case ButtonPress: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEDOWN; break; case 2: tevent.ID=TR_MIDDLEMOUSEDOWN; break; case 3: tevent.ID=TR_RIGHTMOUSEDOWN; break; case 4: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_UPARROW; break; case 5: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_DOWNARROW; break; default: tevent.ID=TR_LEFTMOUSEDOWN; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case ButtonRelease: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEUP; break; case 2: tevent.ID=TR_MIDDLEMOUSEUP; break; case 3: tevent.ID=TR_RIGHTMOUSEUP; break; default: tevent.ID=TR_LEFTMOUSEUP; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case EnterNotify: case LeaveNotify: X11_ResetKeysUpDowns(); break; case MotionNotify: // printf("%d %d %d\n",((XMotionEvent *)&event)->x,((XMotionEvent *)&event)->y,((XMotionEvent *)&event)->state); tevent.ID=TR_MOUSEMOVE; tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; //case VisibilityNotify: // case ConfigureNotify: case ConfigureNotify: if( window->width!=((XConfigureEvent *)&event)->width || window->height!=((XConfigureEvent *)&event)->height ) { #if 0 fprintf(stderr,"Resized %d %d\n", ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); #endif XFreePixmap( x11_display, window->os_visual->pixmap ); XFreePixmap( x11_display, window->os_visual->cursorpixmap ); window->os_visual->pixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->pixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width,((XConfigureEvent *)&event)->height ); window->os_visual->cursorpixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->cursorpixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); Resize_resized( window, ((XConfigureEvent *)&event)->width-1, ((XConfigureEvent *)&event)->height-1, true ); } break; case Expose: printf("Expose\n"); //GFX_FilledBox(window,0,0,0,window->width,window->height); //DrawUpTrackerWindow(root->song->tracker_windows); Resize_resized(window,window->width,window->height,false); //XFlush(x11_display); break; case NoExpose: break; case GraphicsExpose: printf("GRaphicsExpose event.\n"); break; case ClientMessage: X11Event_ClientMessage((XClientMessageEvent *)&event,window); // printf("Received \"%s\"\n",((XClientMessageEvent *)&event)->data.b); break; default: printf("Unknown xevent %d\n",event.type); break; } } } EndProgram(); } posix_EndPlayer(); unlockGUI(); EndGuiThread(); XCloseDisplay(x11_display); return 0; }
// // AbiPaint editImage // ------------------ // This is the function that we actually call to invoke the image editor. // // parameters are: // AV_View* v // EV_EditMethodCallData *d // static DECLARE_ABI_PLUGIN_METHOD(editImage) { UT_UNUSED(v); // Get the current view that the user is in. XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView()); // // get values from preference (initial plugin execution should have set sensible defaults) // UT_String imageApp; // holds MAXPATH\appName <space> MAXPATH\imagefilename bool bLeaveImageAsPNG; // read stuff from the preference value if (!prefsScheme->getValue(ABIPAINT_PREF_KEY_szProgramName, imageApp)) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); getDefaultApp(imageApp, bLeaveImageAsPNG); } // now that we have program name, try to get other flag (allows overriding default value) // Note: we allow overriding, otherwise if we don't adhere to user's setting // then the use BMP or not menu should be greyed to note it has no effect prefsScheme->getValueBool(ABIPAINT_PREF_KEY_bLeaveImageAsPNG, &bLeaveImageAsPNG); // // generate a temp file name... // char *szTempFileName = NULL; GError *err = NULL; gint fp = g_file_open_tmp ("XXXXXX", &szTempFileName, &err); if (err) { g_warning ("%s", err->message); g_error_free (err); err = NULL; return FALSE; } close(fp); UT_String szTmpPng = szTempFileName; szTmpPng += ".png"; UT_String szTmp = szTmpPng; // default: our temp file is the created png file PT_DocPosition pos = pView->saveSelectedImage((const char *)szTmpPng.c_str()); if(pos == 0) { remove(szTempFileName); g_free (szTempFileName); szTempFileName = NULL; pFrame->showMessageBox("You must select an Image before editing it", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); return false; } #ifdef ENABLE_BMP // // Convert png into bmp for best compatibility with Windows programs // NOTE: probably looses detail/information though!!! so if possible use PNG // if (!bLeaveImageAsPNG) { szTmp = szTempFileName; szTmp += ".bmp"; // our temp file is a bmp file if (convertPNG2BMP(szTmpPng.c_str(), szTmp.c_str())) { pFrame->showMessageBox("Unable to convert PNG image data to BMP for external program use!", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); UT_ASSERT(UT_SHOULD_NOT_HAPPEN); remove(szTempFileName); g_free (szTempFileName); szTempFileName = NULL; remove(szTmpPng.c_str()); return false; } // remove(szTmpPng.c_str()); } #endif // remove the temp file (that lacks proper extension) remove(szTempFileName); g_free (szTempFileName); szTempFileName = NULL; // // Get the initial file status. // struct stat myFileStat; int ok = stat(szTmp.c_str(),&myFileStat); if(ok < 0) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); remove(szTmpPng.c_str()); remove(szTmp.c_str()); // should silently fail if exporting as PNG file return false; } time_t mod_time = myFileStat.st_mtime; // // Fire up the image editor... // ProcessInfo procInfo; if (!createChildProcess(imageApp.c_str(), szTmp.c_str(), &procInfo)) { UT_String msg = "Unable to run program: "; msg += imageApp + " " + szTmp; pFrame->showMessageBox(msg.c_str(), XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); // failed to spawn stuff, so do some cleanup and return failure remove(szTmpPng.c_str()); remove(szTmp.c_str()); // should silently fail if exporting as PNG file return false; } lockGUI(d); while (isProcessStillAlive(procInfo)) { UT_usleep(10000); // wait 10 milliseconds pFrame->nullUpdate(); ok = stat(szTmp.c_str(),&myFileStat); if(ok == 0) { if(myFileStat.st_mtime != mod_time) { // wait for changes to settle (program done writing changes) // we use both modified time & file size, but really we // could just use file size as mod time doesn't appear to change for small images mod_time = myFileStat.st_mtime; off_t size = myFileStat.st_size; UT_usleep(100000); // wait 100 milliseconds (so program may have time to write something) ok = stat(szTmp.c_str(),&myFileStat); while((mod_time != myFileStat.st_mtime) || !size || (size > 0 && size != myFileStat.st_size)) { mod_time = myFileStat.st_mtime; size = myFileStat.st_size; ok = stat(szTmp.c_str(),&myFileStat); UT_usleep(500000); // wait a while, let program write its data // just make sure the program is still running, otherwise we could get stuck in a loop if (!isProcessStillAlive(procInfo)) { pFrame->showMessageBox("External image editor appears to have been terminated unexpectedly.", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); //procInfo.hProcess = 0; goto Cleanup; } } mod_time = myFileStat.st_mtime; UT_usleep(100000); // wait a while just to make sure program is done with file // // OK replace the current image with this. // IEGraphicFileType iegft = IEGFT_Unknown; FG_Graphic* pFG; UT_Error errorCode; #ifdef ENABLE_BMP // // Convert bmp back to png (as we can not assume AbiWord has builtin BMP support [as its now an optional plugin]) // NOTE: probably looses detail/information though!!! so if possible use only PNG // if (!bLeaveImageAsPNG) { if (convertBMP2PNG(szTmp.c_str(), szTmpPng.c_str())) { pFrame->showMessageBox("Unable to convert BMP image data back to PNG for AbiWord to import!", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); UT_ASSERT(UT_SHOULD_NOT_HAPPEN); goto Cleanup; } } #endif errorCode = IE_ImpGraphic::loadGraphic(szTmpPng.c_str(), iegft, &pFG); if(errorCode) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); pFrame->showMessageBox("Error making pFG. Could not put image back into Abiword", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); goto Cleanup; } unlockGUI(d); pView->cmdUnselectSelection(); pView->setPoint(pos); pView->extSelHorizontal(true, 1); // move point forward one errorCode = pView->cmdInsertGraphic(pFG); if (errorCode) { pFrame->showMessageBox("Could not put image back into Abiword", XAP_Dialog_MessageBox::b_O,XAP_Dialog_MessageBox::a_OK); UT_ASSERT(UT_SHOULD_NOT_HAPPEN); DELETEP(pFG); goto Cleanup; } DELETEP(pFG); // // Reselect the image // pView->setPoint(pos); pView->extSelHorizontal(true, 1); // move point forward one lockGUI(d); } } } // // Normal exit, delete the tempfile and return success // remove(szTmpPng.c_str()); remove(szTmp.c_str()); // should silently fail if exporting as PNG file unlockGUI(d); return true; // // Something went wrong. // Cleanup: remove(szTmpPng.c_str()); remove(szTmp.c_str()); // should silently fail if exporting as PNG file unlockGUI(d); // // Kill the image editor. // endProcess(procInfo); return false; }