void SatellitesComponent::updateTLEs() { int i = 0; QProgressDialog progressDlg( i18n( "Update TLEs..." ), i18n( "Abort" ), 0, m_groups.count() ); progressDlg.setWindowModality( Qt::WindowModal ); progressDlg.setValue( 0 ); foreach ( SatelliteGroup *group, m_groups ) { if ( progressDlg.wasCanceled() ) return; if( group->tleUrl().isEmpty() ) continue; progressDlg.setLabelText( i18n( "Update %1 satellites", group->name() ) ); KIO::Job* getJob = KIO::file_copy(group->tleUrl(), group->tleFilename(), -1, KIO::Overwrite | KIO::HideProgressInfo ); if( getJob->exec() ) { group->readTLE(); group->updateSatellitesPos(); progressDlg.setValue( ++i ); } else { getJob->uiDelegate()->showErrorMessage(); } } }
bool CaptureManager::OpenMovie_initialize(MyCapture &capture) { if (!capture.IsOK()) return false; frameCount = capture.frameCount; totalFrameCount = frameCount; slideCount = 1; fps = capture.fps ? capture.fps : Preferences::GetSavingFpsDefault(); book = new ImagePlus*[frameCount]; wxProgressDialog progressDlg(_T("Loading movie..."), wxString::Format(_T("Frame 0 of %d"), frameCount),frameCount, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE); for (int i=0; i<totalFrameCount; i++){ progressDlg.Update(i+1, wxString::Format(_T("Frame %d of %d"), i+1, totalFrameCount)); IplImage *newframe = capture.queryFrame(i); IplImage *resized; if (i == 0){ size = cvSize(newframe->width, newframe->height); book[i] = new ImagePlus(newframe); } else if(!cvSizeEquals(newframe, size)){ resized = cvCloneImage(book[0]->orig); cvResize(newframe, resized); book[i] = new ImagePlus(resized); cvReleaseImage(&resized); } else book[i] = new ImagePlus(newframe); } if (BookChangeListener) BookChangeListener->OnBookChange(); SetPos(0); return true; }
bool CaptureManager::SaveMovie(const char* avi) { bool resize = false; CvSize newsize = size; if ( Preferences::GetSavingSizeOverride() && !cvSizeEquals(Preferences::GetSavingSize(), size) ){ resize = true; newsize = Preferences::GetSavingSize(); } CvVideoWriter* writer = cvCreateVideoWriter(avi, Preferences::GetSavingCodec(), Preferences::GetSavingFpsOverride() || !fps ? Preferences::GetSavingFpsDefault() : fps, newsize, 1); IplImage *resized; if (resize) resized = cvCreateImage(newsize,8,3); IplImage *frame_flip = cvCreateImage(newsize,8,3); wxProgressDialog progressDlg(_T("Saving movie..."), wxString::Format(_T("Frame 0 of %d"), frameCount),frameCount, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE); for (int i=0; i<frameCount; i++) { progressDlg.Update(i+1, wxString::Format(_T("Frame %d of %d"), i+1, frameCount)); if (resize) cvResize(book[i*offset]->ToIplImage(), resized); else resized = book[i*offset]->ToIplImage(); cvConvertImage( resized, frame_flip, CV_CVTIMG_SWAP_RB ); cvWriteFrame(writer, frame_flip); } cvReleaseVideoWriter(&writer); cvReleaseImage(&frame_flip); frame_flip = NULL; if (resize) cvReleaseImage(&resized); return true; }
void LIB_EDIT_FRAME::SyncLibraries( bool aShowProgress ) { LIB_ID selected; if( m_treePane ) selected = m_treePane->GetLibTree()->GetSelectedLibId(); if( aShowProgress ) { wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString, m_libMgr->GetAdapter()->GetLibrariesCount(), this ); m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName ) { progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ), libName ) ); } ); } else { m_libMgr->Sync( true ); } if( m_treePane ) { wxDataViewItem found; if( selected.IsValid() ) { // Check if the previously selected item is still valid, // if not - it has to be unselected to prevent crash found = m_libMgr->GetAdapter()->FindItem( selected ); if( !found ) m_treePane->GetLibTree()->Unselect(); } m_treePane->Regenerate(); // Try to select the parent library, in case the part is not found if( !found && selected.IsValid() ) { selected.SetLibItemName( "" ); found = m_libMgr->GetAdapter()->FindItem( selected ); if( found ) m_treePane->GetLibTree()->SelectLibId( selected ); } // If no selection, see if there's a current part to centre if( !selected.IsValid() && GetCurPart() ) { LIB_ID current( GetCurLib(), GetCurPart()->GetName() ); m_treePane->GetLibTree()->CenterLibId( current ); } } }
void FileManagerAddDlg::slotBtnOk() { const QList<QListWidgetItem *> itemsToAdd = listWidget.selectedItems(); QProgressDialog progressDlg("Reading file tags...", "Abbrechen", 0, listWidget.selectedItems().size(), this); progressDlg.setWindowModality(Qt::WindowModal); sqlhelper.start_insert_sequence(); for(int cnt = 0; cnt != itemsToAdd.size(); ++cnt) { #if 0 //QString insert_cmd("INSERT INTO `musicdb`.`main` (`id` ,`titel` ,`kuenstler` ,`album` ,`tag` ,`genre` ,`jahr` ,`philipp` ,`johannes` ,`dateityp` ,`qualitaet` ,`bew_joh` ,`bew_phil` ,`pfad`) VALUES (NULL , '"); QString insert_cmd("NULL , '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("1"); insert_cmd.append("', '"); insert_cmd.append("1"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); insert_cmd.append("', '"); QString _filename = itemsToAdd[cnt]->text(); _filename.replace('\'', "\\'"); insert_cmd.append(_filename); insert_cmd.append("'"); printf("Insert command: %s\n", insert_cmd.toAscii().data()); sqlhelper.INSERT(insert_cmd); #else progressDlg.setValue(cnt); progressDlg.show(); if (progressDlg.wasCanceled()) break; sqlhelper.INSERT(itemsToAdd[cnt]->text().toAscii().data()); #endif } sqlhelper.stop_insert_sequence(); if(itemsToAdd.size() > 0) accept(); }
void SatellitesComponent::updateTLEs() { int i = 0; QProgressDialog progressDlg( i18n( "Update TLEs..." ), i18n( "Abort" ), 0, m_groups.count() ); progressDlg.setWindowModality( Qt::WindowModal ); progressDlg.setValue( 0 ); foreach ( SatelliteGroup *group, m_groups ) { if ( progressDlg.wasCanceled() ) return; if( group->tleUrl().isEmpty() ) continue; progressDlg.setLabelText( i18n( "Update %1 satellites", group->name() ) ); progressDlg.setWindowTitle(i18n("Satellite Orbital Elements Update")); QNetworkAccessManager manager; QNetworkReply *response = manager.get(QNetworkRequest(group->tleUrl())); // Wait synchronously QEventLoop event; QObject::connect(response,SIGNAL(finished()),&event,SLOT(quit())); event.exec(); if (response->error() == QNetworkReply::NoError) { QFile file(group->tleFilename().toLocalFile()); if (file.open(QFile::WriteOnly)) { file.write(response->readAll()); file.close(); group->readTLE(); group->updateSatellitesPos(); progressDlg.setValue( ++i ); } else { KSNotification::error(file.errorString()); return; } } else { KSNotification::error(response->errorString()); return; } } }
void frmScanforDevices::getNodeInfo( wxCommandEvent& event ) { CMDF mdf; wxString url; wxBusyCursor wait; scanElement *pElement = (scanElement *) m_DeviceTree->GetItemData(m_DeviceTree->GetSelection()); if (NULL != pElement) { wxProgressDialog progressDlg(_("Getting node info."), _("Reading Registers"), 256, this, wxPD_ELAPSED_TIME | wxPD_AUTO_HIDE | wxPD_CAN_ABORT); if (INTERFACE_CANAL == m_interfaceType) { if ( CANAL_ERROR_SUCCESS == m_csw.getDllInterface()->readRegistersfromLevel1Device( pElement->m_nodeid, 0x80, // strat reg 0, // page 128, // count pElement->m_reg + 0x80 ) ) { uint8_t preg_url[33]; memset( preg_url, 0, sizeof(preg_url)); memcpy( preg_url, pElement->m_reg + 0xe0, 32 ); bool bmdf = m_csw.loadMDF( this, preg_url, url, &mdf ); pElement->m_html = vscp_getDeviceHtmlStatusInfo( pElement->m_reg, bmdf ? &mdf : NULL ); m_htmlWnd->SetPage(pElement->m_html); // Mark as loaded pElement->m_bLoaded = true; } else { wxMessageBox(_("Failed to read registers!")); } } else if (INTERFACE_VSCP == m_interfaceType) { cguid destguid; destguid = m_ifguid; destguid.setNicknameID( pElement->m_nodeid ); if ( CANAL_ERROR_SUCCESS == m_csw.getTcpIpInterface()->readLevel2Registers( 0x80, // reg 0, // Page 128, // count pElement->m_reg + 0x80, m_ifguid, &destguid, false ) ) { uint8_t preg_url[33]; memset( preg_url, 0, sizeof(preg_url)); memcpy( preg_url, pElement->m_reg + 0xe0, 32 ); bool bmdf = m_csw.loadMDF( this, preg_url, url, &mdf ); pElement->m_html = vscp_getDeviceHtmlStatusInfo( pElement->m_reg, bmdf ? &mdf : NULL ); m_htmlWnd->SetPage(pElement->m_html); // Mark as loaded pElement->m_bLoaded = true; } else { wxMessageBox(_("Failed to read registers!")); } } } event.Skip(false); }
void frmScanforDevices::OnButtonScanClick(wxCommandEvent& event) { bool bSlowAlgorithm = false; uint8_t val; uint8_t reg[256]; CMDF mdf; wxString url; wxTreeItemId newitem; wxBusyCursor wait; bSlowAlgorithm = m_slowAlgorithm->GetValue(); uint8_t scanFrom = vscp_readStringValue(m_ctrlEditFrom->GetValue()); uint8_t scanTo = vscp_readStringValue(m_ctrlEditTo->GetValue()); if ( scanFrom >= scanTo ) { wxMessageBox(_("Node to scan from must be less then to")); return; } m_DeviceTree->DeleteAllItems(); m_htmlWnd->SetPage( "<html><body></body></html>" ); m_htmlWnd->Update(); wxProgressDialog progressDlg(_("Scanning for VSCP devices"), _("Reading Registers"), 2*(scanTo-scanFrom+1), this, wxPD_ELAPSED_TIME | wxPD_AUTO_HIDE | wxPD_CAN_ABORT); wxTreeItemId rootItem = m_DeviceTree->AddRoot(_("Found device(s)")); m_DeviceTree->ExpandAll(); // Fetch GUID for the interface if ( USE_TCPIP_INTERFACE == m_csw.getDeviceType() ) { fetchIterfaceGUID(); } if ( bSlowAlgorithm ) { for ( int i = scanFrom; i <= scanTo; i++ ) { if (!progressDlg.Update(i, wxString::Format(_("Checking for device %d"), i))) { if (m_DeviceTree->GetCount()) { wxTreeItemIdValue cookie; wxTreeItemId item = m_DeviceTree->GetFirstChild(m_DeviceTree->GetRootItem(), cookie); if ( item.IsOk() ) m_DeviceTree->SelectItem( item ); } ::wxEndBusyCursor(); break; } if ( USE_DLL_INTERFACE == m_csw.getDeviceType() ) { // Empty input queue canalMsg canalmsg; while ( m_csw.getDllInterface()->doCmdDataAvailable() ) { if ( CANAL_ERROR_SUCCESS != m_csw.getDllInterface()->doCmdReceive( &canalmsg ) ) break; } if ( CANAL_ERROR_SUCCESS == m_csw.getDllInterface()->readLevel1Register( i, 0, 0xd0, &val ) ) { newitem = m_DeviceTree->AppendItem(rootItem, wxString::Format(_("Node with nickname=%d"), i)); m_DeviceTree->ExpandAll(); memset(reg, 0, sizeof(reg)); scanElement *pElement = new scanElement; if (NULL != pElement) { pElement->m_bLoaded = false; pElement->m_nodeid = i; //pElement->m_html = str; memset(pElement->m_reg, 0, 256); m_DeviceTree->SetItemData(newitem, pElement); } } } else if (USE_TCPIP_INTERFACE == m_csw.getDeviceType()) { cguid destguid; destguid = m_ifguid; destguid.setLSB(i); // Empty input queue m_csw.getTcpIpInterface()->doCmdClear(); if ( CANAL_ERROR_SUCCESS == m_csw.getTcpIpInterface()->readLevel2Register( 0xd0, 0, &val, m_ifguid, &destguid ) ) { newitem = m_DeviceTree->AppendItem(rootItem, wxString::Format(_("Node with nickname=%d"), i)); m_DeviceTree->ExpandAll(); scanElement *pElement = new scanElement; if (NULL != pElement) { pElement->m_bLoaded = false; pElement->m_nodeid = i; //pElement->m_html = str; memset(pElement->m_reg, 0, 256); m_DeviceTree->SetItemData(newitem, pElement); } } } ::wxSafeYield(); } // for } else { // Fast Algorithm vscpEventEx eventex; if (USE_DLL_INTERFACE == m_csw.getDeviceType()) { // Empty input queue canalMsg canalmsg; while ( m_csw.getDllInterface()->doCmdDataAvailable() ) { if ( CANAL_ERROR_SUCCESS != m_csw.getDllInterface()->doCmdReceive( &canalmsg ) ) break; } // Send read register to all nodes. for ( int i = scanFrom; i <= scanTo; i++ ) { #ifdef WIN32 progressDlg.Update(i, wxString::Format(_("Checking for device %d"), i)); #endif eventex.vscp_class = VSCP_CLASS1_PROTOCOL; eventex.vscp_type = VSCP_TYPE_PROTOCOL_READ_REGISTER; eventex.sizeData = 2; // nodeid + register to read eventex.data[ 0 ] = i; // nodeid eventex.data[ 1 ] = 0xd0; // Register to read m_csw.doCmdSend( &eventex ); wxMilliSleep( 20 ); } // Check for replies wxLongLong resendTime = ::wxGetLocalTimeMillis(); std::list<int> found_list; bool bLevel2 = false; uint8_t cnt = 0; while (true) { progressDlg.Pulse( wxString::Format(_("Found %d"), found_list.size())); while ( m_csw.doCmdDataAvailable() ) { // Message available if ( CANAL_ERROR_SUCCESS == m_csw.doCmdReceive( &eventex ) ) { // Valid event #if 0 { wxString str; str = wxString::Format(_("Received Event: class=%d type=%d size=%d data= "), eventex.vscp_class, eventex.vscp_type, eventex.sizeData ); for ( int ii = 0; ii < eventex.sizeData; ii++ ) { str += wxString::Format(_("%02X "), eventex.data[ii] ); } wxLogDebug(str); } #endif // Level I Read reply? if ( ( VSCP_CLASS1_PROTOCOL == eventex.vscp_class ) && ( VSCP_TYPE_PROTOCOL_RW_RESPONSE == eventex.vscp_type ) ) { if ( 0xd0 == eventex.data[ 0 ] ) { // Requested register? // Add nickname to list found_list.push_back( eventex.GUID[15] ); } } } // valid event } // Event is available if ((::wxGetLocalTimeMillis() - resendTime) > 3000 ) { // Take away duplicates found_list.unique(); wxTreeItemId newitem; for( std::list<int>::iterator list_iter = found_list.begin(); list_iter != found_list.end(); list_iter++) { newitem = m_DeviceTree->AppendItem(rootItem, wxString::Format(_("Node with nickname=%d"), *list_iter)); m_DeviceTree->ExpandAll(); scanElement *pElement = new scanElement; if (NULL != pElement) { pElement->m_bLoaded = false; pElement->m_nodeid = *list_iter; pElement->m_html = _("Right click on item to load info about node."); memset(pElement->m_reg, 0, 256); m_DeviceTree->SetItemData(newitem, pElement); } } break; } } // while } // TCP/IP else if (USE_TCPIP_INTERFACE == m_csw.getDeviceType()) { // Empty input queue m_csw.getTcpIpInterface()->doCmdClear(); // Read register at all nodes. for ( int i=scanFrom; i<=scanTo; i++ ) { cguid destguid; destguid.setLSB(i); eventex.head = VSCP_PRIORITY_NORMAL; eventex.timestamp = 0; eventex.obid = 0; // Check if a specific interface is used if ( !m_ifguid.isNULL() ) { progressDlg.Update(i, wxString::Format(_("Checking for device %d"), i)); eventex.vscp_class = VSCP_CLASS2_LEVEL1_PROTOCOL; eventex.vscp_type = VSCP_TYPE_PROTOCOL_READ_REGISTER; memset(eventex.GUID, 0, 16);// We use GUID for interface eventex.sizeData = 16 + 2; // Interface GUID + nodeid + register to read m_ifguid.writeGUID(eventex.data); eventex.data[ 16 ] = i; // nodeid eventex.data[ 17 ] = 0xd0; // Register to read m_csw.doCmdSend( &eventex ); wxMilliSleep( 10 ); } else { wxMessageBox( _("No interface specified. Please select one") ); goto error; } } // for // Check for replies wxLongLong resendTime = ::wxGetLocalTimeMillis(); std::list<int> found_list; bool bLevel2 = false; uint8_t cnt = 0; while (true) { progressDlg.Pulse( wxString::Format(_("Found %d"), found_list.size())); while ( m_csw.doCmdDataAvailable() ) { // Message available if ( CANAL_ERROR_SUCCESS == m_csw.doCmdReceive( &eventex ) ) { // Valid event #if 0 { wxString str; str = wxString::Format(_("Received Event: class=%d type=%d size=%d data=%d %d"), eventex.vscp_class, eventex.vscp_type, eventex.sizeData, eventex.data[15], eventex.data[16] ); wxLogDebug(str); } #endif // Level I Read reply? if ( ( VSCP_CLASS1_PROTOCOL == eventex.vscp_class ) && (VSCP_TYPE_PROTOCOL_RW_RESPONSE == eventex.vscp_type)) { if (eventex.data[ 0 ] == 0xd0) { // Requested register? // Add nickname to list found_list.push_back( eventex.GUID[ 15 ] ); } // Check for correct node } // Level II 512 Read reply? else if (/*!m_ifguid.isNULL() && !bLevel2 &&*/ (VSCP_CLASS2_LEVEL1_PROTOCOL == eventex.vscp_class) && (VSCP_TYPE_PROTOCOL_RW_RESPONSE == eventex.vscp_type)) { //if ( pdestGUID->isSameGUID( event.GUID ) ) { // Reg we requested? if (0xd0 == eventex.data[ 16 ] ) { // Add nickname to list found_list.push_back( eventex.GUID[ 15 ] ); } //} } // Level II Read reply? else if (m_ifguid.isNULL() && bLevel2 && (VSCP_CLASS2_PROTOCOL == eventex.vscp_class) && (VSCP2_TYPE_PROTOCOL_READ_WRITE_RESPONSE == eventex.vscp_type)) { // from us uint32_t retreg = (eventex.data[ 0 ] << 24) + (eventex.data[ 1 ] << 16) + (eventex.data[ 2 ] << 8) + eventex.data[ 3 ]; // Register we requested? if (retreg == 0xffffffd0) { // Add nickname to list found_list.push_back( eventex.data[ 15 ] ); } } } // valid event } //Event is available if ((::wxGetLocalTimeMillis() - resendTime) > 3000 ) { // Take away duplicates found_list.unique(); wxTreeItemId newitem; for ( std::list<int>::iterator list_iter = found_list.begin(); list_iter != found_list.end(); list_iter++) { newitem = m_DeviceTree->AppendItem(rootItem, wxString::Format(_("Node with nickname=%d"), *list_iter)); m_DeviceTree->ExpandAll(); scanElement *pElement = new scanElement; if (NULL != pElement) { pElement->m_bLoaded = false; pElement->m_nodeid = *list_iter; pElement->m_html = _("Right click on item to load info about node. Double click to open configuration window."); memset(pElement->m_reg, 0, 256); m_DeviceTree->SetItemData( newitem, pElement ); } } break; } // while } } // TCP/IP i/f } // fast if ( m_DeviceTree->GetCount() ) { m_DeviceTree->SelectItem( m_DeviceTree->GetRootItem() ); } error: Raise(); event.Skip(false); }
bool frmScanforDevices::enableInterface(void) { wxProgressDialog progressDlg( _("VSCP Works"), _("Opening interface..."), 100, this, wxPD_ELAPSED_TIME | wxPD_AUTO_HIDE | wxPD_APP_MODAL); progressDlg.Pulse(_("opening interface...")); if ( 0 != m_csw.doCmdOpen() ) { progressDlg.Pulse(_("Interface is open.")); if (USE_DLL_INTERFACE == m_csw.getDeviceType()) { progressDlg.Pulse( _("Checking if interface is working...") ); // We use a dll. // // Verify that we have a connection with the interface // We do that by using the status command. canalStatus canalstatus; if ( CANAL_ERROR_SUCCESS != m_csw.doCmdStatus( &canalstatus ) ) { wxString strbuf; strbuf.Printf( _("Unable to open interface to driver. errorcode=%lu, suberrorcode=%lu, Description: %s"), canalstatus.lasterrorcode, canalstatus.lasterrorsubcode, canalstatus.lasterrorstr); wxLogStatus(strbuf); wxMessageBox(_("No response received from interface. May not work correctly!")); } } else if ( USE_TCPIP_INTERFACE == m_csw.getDeviceType() ) { //m_staticComboText->SetLabel(_("Interface")); progressDlg.Pulse(_("Checking if interface is working...")); // Test if (CANAL_ERROR_SUCCESS != m_csw.doCmdNOOP()) { wxMessageBox(_("Interface test command failed. May not work correctly!")); } // TCP/IP interface progressDlg.Pulse(_("TCP/IP Interface Open")); /////////////////////////////////////////// // Fill listbox with available interfaces /////////////////////////////////////////// // Get the interface list wxString wxstr; wxArrayString strarray; // Get VSCP interface list progressDlg.Pulse(_("TCP/IP Interface Open")); m_csw.getTcpIpInterface()->doCmdInterfaceList(strarray); if (strarray.Count()) { //m_comboNodeID->Clear(); for (unsigned int i = 0; i < strarray.Count(); i++) { wxStringTokenizer tkz(strarray[i], _(",")); wxString strOrdinal = tkz.GetNextToken(); wxString strType = tkz.GetNextToken(); wxString strGUID = tkz.GetNextToken(); wxString strDescription = tkz.GetNextToken(); wxString strLine = strGUID; strLine += _(" "); strLine += _(" Type = "); strLine += strType; strLine += _(" - "); strLine += strDescription; } } else { wxMessageBox(_("No interfaces found!")); } } // TCP/IP interface } else { progressDlg.Pulse(_("Failed to open Interface.")); wxMessageBox(_("Failed to Open Interface.")); return false; } // Move to top of zorder Raise(); return true; }
//Decoded .gnt files based on the parameters. Return true when successfully decoding the files. bool QxMainWindow::decodeFiles(const QStringList& fileList, const QString& strDestinationPath, const QString& imageFormat, const cv::Size& imageSize, const QxDecodeOptionDlg::ApplicationType appType) { // Create a sub-folder in the selected folder to save the decoded images. // If the folder already exists, ask user whether to append decoded images to it. QString strImagePath = strDestinationPath + "/" + g_ImageFolderName; if (!g_dirManager.exists(strImagePath)) { g_dirManager.mkdir(strImagePath); } else { QString strTitle("Folder already exists"); QString strMessage; strMessage.append("There is already a floder named \"").append(g_ImageFolderName).append("\" in the selected folder.\n"); strMessage.append("Do you still want to save the decoded images to it?"); QMessageBox::StandardButton button = QMessageBox::question(this, strTitle, strMessage, QMessageBox::Yes | QMessageBox::No); if (button != QMessageBox::Yes) { return false; } } // Remove former information, just in case the user does twice or more times decoding without restart the software. m_LabelCodeMap.clear(); m_ImageLabelMap.clear(); // decode files QStringList::size_type uFileAmount = fileList.size(); QProgressDialog progressDlg("Decoding files...", "Cancel", 0, uFileAmount, this); progressDlg.setWindowModality(Qt::WindowModal); progressDlg.setMinimumDuration(0); for (QStringList::size_type i = 0; i != fileList.size(); ++i) { //Update progress dialog progressDlg.setValue(i); QApplication::processEvents(); if (progressDlg.wasCanceled()) { saveMappingFile(strDestinationPath, appType); saveLabelFile(strDestinationPath, appType); return false; } //Error handling QString strFileName = fileList.at(i); QFile file(strFileName); if (!file.open(QIODevice::ReadOnly)) { QString strTitle("Open file error"); QString strErrorMessage = "Cannot open selected file:\nFile name: " + strFileName + "\nContinue decoding the remaining files? "; QMessageBox::StandardButton button = QMessageBox::information(this, strTitle, strErrorMessage, QMessageBox::Yes | QMessageBox::No); if (button == QMessageBox::Yes) { continue; } else { return false; } } //Decode .gnt file specified by strFileName. QByteArray rawData = file.readAll(); file.close(); quint32 uDecodedByteNum = 0; const quint32 uTotalByteNum = rawData.size(); while (uDecodedByteNum != uTotalByteNum) { quint32 uTagCode = uchar(rawData.at(5 + uDecodedByteNum)) + quint32(uchar(rawData.at(4 + uDecodedByteNum))) * (1 << 8); quint32 uWidth = uchar(rawData.at(6 + uDecodedByteNum)) + quint32(uchar(rawData.at(7 + uDecodedByteNum))) * (1 << 8); quint32 uHeight = uchar(rawData.at(8 + uDecodedByteNum)) + quint32(uchar(rawData.at(9 + uDecodedByteNum))) * (1 << 8); quint32 uArcLen = uWidth > uHeight ? uWidth : uHeight; uDecodedByteNum += 10; /* A character should be presented in a square. However, decoded images are, in most cases, rectangle. Therefore, a decoded character image is padded to a square whose length of the side is uArcLen (longer edge of the rectangle). As the background of the decoded images is white (pixel value 255 for 8-bit grayscale images), all the padded pixels are set to be 255. */ cv::Mat img = 255 * cv::Mat::ones(uArcLen, uArcLen, CV_8UC1); int iHalfPadRowNum = (uArcLen - uHeight) / 2; int iHalfPadColNum = (uArcLen - uWidth) / 2; for (quint32 row = iHalfPadRowNum; row < uHeight + iHalfPadRowNum; ++row) { uchar *pRow = img.ptr<uchar>(row); for (quint32 col = iHalfPadColNum; col < uWidth + iHalfPadColNum; ++col) { pRow[col] = uchar(rawData.at(uDecodedByteNum++)); } } // update mapping table, because label of the input images should, optimally, start from 0 and be consecutive. if (!m_LabelCodeMap.contains(uTagCode)) { quint32 uNewLabel = m_LabelCodeMap.size(); m_LabelCodeMap[uTagCode] = uNewLabel; } // image normalization and saving QString strSaveFileName = getSaveImageName(strImagePath, uTagCode, i + 1, appType); strSaveFileName += "." + imageFormat; cv::resize(img, img, imageSize); cv::imwrite(strSaveFileName.toStdString(), img); m_ImageLabelMap[strSaveFileName] = m_LabelCodeMap[uTagCode]; } } // Save the .txt files for different software saveMappingFile(strDestinationPath, appType); saveLabelFile(strDestinationPath, appType); progressDlg.setValue(uFileAmount); return true; }
ComicBookRAR::ComicBookRAR(wxString file, wxUint32 cacheLen, COMICAL_ZOOM zoom, long zoomLevel, bool fitOnlyOversize, COMICAL_MODE mode, FREE_IMAGE_FILTER filter, COMICAL_DIRECTION direction, wxInt32 scrollbarThickness) : ComicBook(file, cacheLen, zoom, zoomLevel, fitOnlyOversize, mode, filter, direction, scrollbarThickness) { HANDLE rarFile; int RHCode = 0, PFCode = 0; struct RARHeaderDataEx header; struct RAROpenArchiveDataEx flags; wxString path, new_password; wxInputStream *stream; ComicPage *page; int numEntries, progress=0; open_rar: rarFile = openRar(&flags, &header, RAR_OM_LIST); if (flags.Flags & 0x0080) { // if the headers are encrypted new_password = wxGetPasswordFromUser( wxT("This archive is password-protected. Please enter the password."), wxT("Enter Password")); if (new_password.IsEmpty()) { // the dialog was cancelled, and the archive cannot be opened closeRar(rarFile, &flags); throw ArchiveException(filename, wxT("Comical could not open this file because it is password-protected.")); } SetPassword(new_password.ToAscii()); } if (password) RARSetPassword(rarFile, password); // skip through the entire archive to count the number of entries for (numEntries = 0; RARReadHeaderEx(rarFile, &header) == 0; numEntries++) { if ((PFCode = RARProcessFile(rarFile, RAR_SKIP, NULL, NULL)) != 0) { closeRar(rarFile, &flags); throw ArchiveException(filename, ProcessFileError(PFCode, header.FileNameW)); } } wxProgressDialog progressDlg(wxString(wxT("Opening ")) + file, wxString(), numEntries); progressDlg.SetMinSize(wxSize(400, -1)); // close and re-open the archive to restart at the first header closeRar(rarFile, &flags); rarFile = openRar(&flags, &header, RAR_OM_LIST); while ((RHCode = RARReadHeaderEx(rarFile, &header)) == 0) { path = header.FileNameW; progressDlg.Update(progress, wxString(wxT("Scanning: ")) + path); progressDlg.CentreOnParent(wxHORIZONTAL); stream = ExtractStream(path); page = new ComicPage(path, stream); if (page->GetBitmapType() == wxBITMAP_TYPE_INVALID) delete page; else Pages.push_back(page); wxDELETE(stream); if ((PFCode = RARProcessFileW(rarFile, RAR_SKIP, NULL, NULL)) != 0) { closeRar(rarFile, &flags); throw ArchiveException(filename, ProcessFileError(PFCode, path)); } progressDlg.Update(++progress); } closeRar(rarFile, &flags); // Wrong return code + needs password = wrong password given if (RHCode != ERAR_END_ARCHIVE && flags.Flags & 0x0080) goto open_rar; postCtor(); Create(); // create the wxThread }
void frmScanforDevices::getNodeInfo(wxCommandEvent& event) { CMDF mdf; wxString url; scanElement *pElement = (scanElement *) m_DeviceTree->GetItemData(m_DeviceTree->GetSelection()); if (NULL != pElement) { wxProgressDialog progressDlg(_("Getting node info."), _("Reading Registers"), 256, this, wxPD_ELAPSED_TIME | wxPD_AUTO_HIDE | wxPD_CAN_ABORT); if (INTERFACE_CANAL == m_interfaceType) { bool bregs = m_csw.readLevel1Registers( this, pElement->m_reg, pElement->m_nodeid, 0, 256, &progressDlg ); uint8_t preg_url[33]; memset( preg_url, 0, sizeof(preg_url)); memcpy( preg_url, pElement->m_reg + 0xe0, 32 ); bool bmdf = m_csw.loadMDF( this, preg_url, url, &mdf ); pElement->m_html = vscp_getDeviceHtmlStatusInfo( pElement->m_reg, bmdf ? &mdf : NULL ); m_htmlWnd->SetPage(pElement->m_html); // Mark as loaded if ( bregs ) pElement->m_bLoaded = true; } else if (INTERFACE_VSCP == m_interfaceType) { cguid destguid; destguid.setLSB( pElement->m_nodeid ); bool bregs = m_csw.readLevel2Registers( this, pElement->m_reg, m_ifguid, 0, 256, &destguid, &progressDlg, false ); // If read fails abort if (!bregs) return; uint8_t preg_url[33]; memset( preg_url, 0, sizeof(preg_url)); memcpy( preg_url, pElement->m_reg + 0xe0, 32 ); bool bmdf = m_csw.loadMDF( this, preg_url, url, &mdf ); pElement->m_html = vscp_getDeviceHtmlStatusInfo( pElement->m_reg, bmdf ? &mdf : NULL ); m_htmlWnd->SetPage(pElement->m_html); // Mark as loaded if ( bregs ) pElement->m_bLoaded = true; } } event.Skip(false); }
void ConjunctionsTool::slotCompute (void) { KStarsDateTime dtStart = startDate -> dateTime(); // Start date KStarsDateTime dtStop = stopDate -> dateTime(); // Stop date long double startJD = dtStart.djd(); // Start julian day long double stopJD = dtStop.djd(); // Stop julian day bool opposition = false; // true=opposition, false=conjunction if( Opposition->currentIndex() ) opposition = true; QStringList objects; // List of sky object used as Object1 KStarsData *data = KStarsData::Instance(); int progress = 0; // Check if we have a valid angle in maxSeparationBox dms maxSeparation( 0.0 ); bool ok; maxSeparation = maxSeparationBox->createDms( true, &ok ); if( !ok ) { KMessageBox::sorry( 0, i18n("Maximum separation entered is not a valid angle. Use the What's this help feature for information on how to enter a valid angle") ); return; } // Check if Object1 and Object2 are set if( FilterTypeComboBox->currentIndex() == 0 && !Object1 ) { KMessageBox::sorry( 0, i18n("Please select an object to check conjunctions with, by clicking on the \'Find Object\' button.") ); return; } Object2 = KSPlanetBase::createPlanet( Obj2ComboBox->currentIndex() ); if( FilterTypeComboBox->currentIndex() == 0 && Object1->name() == Object2->name() ) { // FIXME: Must free the created Objects KMessageBox::sorry( 0 , i18n("Please select two different objects to check conjunctions with.") ); return; } // Init KSConjunct object KSConjunct ksc; connect( &ksc, SIGNAL(madeProgress(int)), this, SLOT(showProgress(int)) ); ksc.setGeoLocation( geoPlace ); switch ( FilterTypeComboBox->currentIndex() ) { case 1: // All object types foreach( int type, data->skyComposite()->objectNames().keys() ) objects += data->skyComposite()->objectNames( type ); break; case 2: // Stars objects += data->skyComposite()->objectNames( SkyObject::STAR ); objects += data->skyComposite()->objectNames( SkyObject::CATALOG_STAR ); break; case 3: // Solar system objects += data->skyComposite()->objectNames( SkyObject::PLANET ); objects += data->skyComposite()->objectNames( SkyObject::COMET ); objects += data->skyComposite()->objectNames( SkyObject::ASTEROID ); objects += data->skyComposite()->objectNames( SkyObject::MOON ); objects += i18n("Sun"); // Remove Object2 planet objects.removeAll( Object2->name() ); break; case 4: // Planet objects += data->skyComposite()->objectNames( SkyObject::PLANET ); // Remove Object2 planet objects.removeAll( Object2->name() ); break; case 5: // Comet objects += data->skyComposite()->objectNames( SkyObject::COMET ); break; case 6: // Ateroid objects += data->skyComposite()->objectNames( SkyObject::ASTEROID ); break; case 7: // Open Clusters objects = data->skyComposite()->objectNames( SkyObject::OPEN_CLUSTER ); break; case 8: // Open Clusters objects = data->skyComposite()->objectNames( SkyObject::GLOBULAR_CLUSTER ); break; case 9: // Gaseous nebulae objects = data->skyComposite()->objectNames( SkyObject::GASEOUS_NEBULA ); break; case 10: // Planetary nebula objects = data->skyComposite()->objectNames( SkyObject::PLANETARY_NEBULA ); break; case 11: // Galaxies objects = data->skyComposite()->objectNames( SkyObject::GALAXY ); break; } // Remove all Jupiter and Saturn moons // KStars crash if we compute a conjunction between a planet and one of this moon if ( FilterTypeComboBox->currentIndex() == 1 || FilterTypeComboBox->currentIndex() == 3 || FilterTypeComboBox->currentIndex() == 6 ) { objects.removeAll( "Io" ); objects.removeAll( "Europa" ); objects.removeAll( "Ganymede" ); objects.removeAll( "Callisto" ); objects.removeAll( "Mimas" ); objects.removeAll( "Enceladus" ); objects.removeAll( "Tethys" ); objects.removeAll( "Dione" ); objects.removeAll( "Rhea" ); objects.removeAll( "Titan" ); objects.removeAll( "Hyperion" ); objects.removeAll( "Iapetus" ); } if ( FilterTypeComboBox->currentIndex() != 0 ) { // Show a progress dialog while processing QProgressDialog progressDlg( i18n( "Compute conjunction..." ), i18n( "Abort" ), 0, objects.count(), this); progressDlg.setWindowModality( Qt::WindowModal ); progressDlg.setValue( 0 ); foreach( QString object, objects ) { // If the user click on the 'cancel' button if ( progressDlg.wasCanceled() ) break; // Update progress dialog ++progress; progressDlg.setValue( progress ); progressDlg.setLabelText( i18n( "Compute conjunction between %1 and %2", Object2->name(), object ) ); // Compute conjuction Object1 = data->skyComposite()->findByName( object ); showConjunctions( ksc.findClosestApproach(*Object1, *Object2, startJD, stopJD, maxSeparation, opposition), object, Object2->name() ); } progressDlg.setValue( objects.count() ); } else {
void WIZARD_FPLIB_TABLE::setupReview() { wxBeginBusyCursor(); updateLibraries(); int libTotalCount = m_libraries.size(); int libCount = 0; bool validate = true; wxProgressDialog progressDlg( _( "Please wait..." ), _( "Validating libraries" ), libTotalCount, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE ); m_dvLibName->SetWidth( 280 ); // Prepare the review list m_listCtrlReview->DeleteAllItems(); for( std::vector<LIBRARY>::iterator it = m_libraries.begin(); it != m_libraries.end(); ++it ) { wxVector<wxVariant> row; LIBRARY::STATUS status = it->GetStatus(); // Check if the library contents is valid if( status == LIBRARY::NOT_CHECKED && validate ) { it->Test(); status = it->GetStatus(); } row.push_back( wxVariant( it->GetDescription() ) ); switch( it->GetStatus() ) { case LIBRARY::NOT_CHECKED: row.push_back( wxVariant( _( "NOT CHECKED" ) ) ); break; case LIBRARY::OK: row.push_back( wxVariant( _( "OK" ) ) ); break; case LIBRARY::INVALID: row.push_back( wxVariant( _( "INVALID" ) ) ); break; } row.push_back( wxVariant( it->GetPluginName() ) ); m_listCtrlReview->AppendItem( row ); ++libCount; if( !progressDlg.Update( libCount, wxString::Format( _( "Validating libraries %d/%d" ), libCount, libTotalCount ) ) ) validate = false; } // The list should never be empty, but who knows? enableNext( m_listCtrlReview->GetItemCount() > 0 ); wxEndBusyCursor(); }