Ejemplo n.º 1
0
bool EventRecorder::mouseClick(button b, state s, modifier m, int x, int y)
{
    if (isRecording) {
        recordedEvents.push_back(Event(Event::MOUSE, (int) m, (int) b, (int) s, x, y));
        saveEvents();
    } else if (isPlaying) {
        return true;
    }
    return next != NULL && next->mouseClick(b, s, m, x, y);
}
Ejemplo n.º 2
0
bool EventsModel::deleteEvent(const QString& eventName)
{
    if (!m_eventNames.contains(eventName)) {
        return false;
    }

    auto eventIndex = m_eventNames.indexOf(eventName);

    beginRemoveRows(QModelIndex(), eventIndex, eventIndex);
    m_eventNames.removeAt(eventIndex);
    m_events.remove(eventName);
    endRemoveRows();

    saveEvents();
    return true;
}
Ejemplo n.º 3
0
bool EventRecorder::keyTyped(unsigned char c, modifier m, int x, int y)
{
    if (c == 'p') {
        isPlaying = ! isPlaying;
        return true;
    }

    if (isRecording) {
        recordedEvents.push_back(Event(Event::KEYBOARD, (int) m, c, x, y, 0));
        saveEvents();
        if (c == 27) {
            specialKey(KEY_F12, m, x, y);
        }
    } else if (isPlaying) {
        if (c == 27) {
            ::exit(0);
        }
        return true;
    }
    return next != NULL && next->keyTyped(c, m, x, y);
}
Ejemplo n.º 4
0
bool EventsModel::addOrEditEvent(const QString& eventName, const QDate& startDate, const QDate& endDate)
{
    if (startDate > endDate ) {
        return false;
    }

    if (m_eventNames.contains(eventName)) {
        m_events[eventName] = QPair<QDate,QDate>(startDate, endDate);

        auto row = m_eventNames.indexOf(eventName);
        dataChanged(index(row), index(row));
    } else {
        beginInsertRows(QModelIndex(), rowCount(), rowCount());

        m_eventNames.append(eventName);
        m_events.insert(eventName, QPair<QDate,QDate>(startDate, endDate));

        endInsertRows();
    }

    saveEvents();
    return true;
}
Ejemplo n.º 5
0
// ---
void VSWContentPrjSaver::saveProject (VSWContentProjectPt cntPrj,
	const std::string& fName, QBOOLEAN saveAll)
{
#ifdef __DEBUGSYSTEM
__KEEPENTRYSIMPLETRACE
#endif

	// Gets the real name of the file...
	// Initialy it is the name received as parameter,
	// but it is null, it will be the name keeped
	// into the aditional data of the content project object.
	// if that data does not exist, it will be not possible to open the file
	// and an exception will be thrown.
	// The method can be used to save an to save as a content project.
	std::string fileName = fName;
	if (fName == std::string (__NULL_STRING__))
		if (cntPrj -> _aditionalData.exists (std::string (__GENVALUE_DESCRIPTORPATH__)))
			fileName = cntPrj -> 
				_aditionalData.getStr (std::string (__GENVALUE_DESCRIPTORPATH__)) 
					-> value ().asString ();
		else
			throw VSWContentSaverError (__DATAEXCEP (_IMPOSIBLEOPENAFILE_TXTERROR_));

	// Extract the location path of the reproduction project description file...
	std::string pathForFile = onlyPath (fileName);

	// Open the file.
	// If not an exception will be thrown...
	std::ofstream file;
	std::string txtToSave (__NULL_STRING__);	
	file.open (fileName.c_str ()); 
	if (!file)
		throw VSWContentSaverError (__DATAEXCEP (_IMPOSIBLEOPENAFILE_TXTERROR_));

	// Save the contents, schedulings, and sequences, 
	// and create the list of them for this file.
	try
	{
		// Gets the docType tag, only if exists...
		std::string docType (__NULL_STRING__);
		if (cntPrj -> _aditionalData.exists (std::string (__GENVALUE_DOCTYPENAME__)))
			docType = std::string ("<!DOCTYPE ") + 
				std::string (cntPrj -> _aditionalData.getStr (std::string (__GENVALUE_DOCTYPENAME__)) -> value ().asString ()) + 
				std::string (" SYSTEM \"") + relPathFor (cntPrj -> _aditionalData.getStr (std::string (__GENVALUE_DOCTYPEDTD__)) -> value ().asString (), pathForFile) + 
				std::string ("\">\n");

		txtToSave += std::string ("\t<") + 
			std::string (__ELEMENTSXML_TAGNAME__) + std::string (">\n");
		txtToSave += saveContents (cntPrj, pathForFile, saveAll);
		txtToSave += saveSequences (cntPrj, pathForFile, saveAll);
		txtToSave += saveSchedulings (cntPrj, pathForFile, saveAll);
		txtToSave += saveEvents (cntPrj);
		txtToSave += std::string ("\t</") + 
			std::string (__ELEMENTSXML_TAGNAME__) + std::string (">\n");
		txtToSave =	// Saves the header, and the paths...
			std::string (__HEADERXML_TAGNAME__) +
			docType + 
			std::string ("<") + std::string (__CONTENTPROJECTXML_TAGNAME__) + 
			std::string (" name=\"") + cntPrj -> name () + std::string ("\">\n") +
			std::string ("\t<") + std::string (__PRJPATHXML_TAGNAME__) + 
			std::string (">\n") + extractPathsFrom (cntPrj, pathForFile) +
			std::string ("\t</") + std::string (__PRJPATHXML_TAGNAME__) + 
			std::string (">\n") + txtToSave + std::string ("</") + 
			std::string (__CONTENTPROJECTXML_TAGNAME__) + std::string (">\n");
	}
	catch (CMTYException& excep)
	{
		throw VSWContentSaverError (excep, /* more deep in the history */
			__DATAEXCEP (_IMPOSIBLETOSAVEFILE_TXTERROR_));
	}

	// Save the content...
	file << txtToSave;
	file.close (); // ...and finaly close the file.

#ifdef __DEBUGSYSTEM
__KEEPEXITSIMPLETRACE
#endif
}
Ejemplo n.º 6
0
// This runs automatically when application is shutting down.
void Calendar::closeEvent(QCloseEvent *event)
{
    saveEvents();
}
Ejemplo n.º 7
0
/** The main function for the background thread
 *
 * Loops until the forground thread requests it to stop.  Reads data from the
 *network,
 * parses it and stores the resulting events (and other metadata) in a temporary
 * workspace.
 */
void ISISLiveEventDataListener::run() {

  try {
    if (!m_isConnected) // sanity check
    {
      throw std::runtime_error(std::string("No connection to the DAE."));
    }

    TCPStreamEventDataNeutron events;
    while (!m_stopThread) {
      // get the header with the type of the packet
      Receive(events.head, "Events header",
              "Corrupt stream - you should reconnect.");
      if (!(events.head.type == TCPStreamEventHeader::Neutron)) {
        // don't know what to do with it - stop
        throw std::runtime_error("Unknown packet type.");
      }
      CollectJunk(events.head);

      // get the header with the sream size
      Receive(events.head_n, "Neutrons header",
              "Corrupt stream - you should reconnect.");
      CollectJunk(events.head_n);

      // absolute pulse (frame) time
      Mantid::Kernel::DateAndTime pulseTime =
          m_startTime + static_cast<double>(events.head_n.frame_time_zero);
      // Save the pulse charge in the logs
      double protons = static_cast<double>(events.head_n.protons);
      m_eventBuffer[0]
          ->mutableRun()
          .getTimeSeriesProperty<double>(PROTON_CHARGE_PROPERTY)
          ->addValue(pulseTime, protons);

      events.data.resize(events.head_n.nevents);
      uint32_t nread = 0;
      // receive the events
      while (nread < events.head_n.nevents) {
        int ntoread = m_socket.available() /
                      static_cast<int>(sizeof(TCPStreamEventNeutron));
        if (ntoread > static_cast<int>(events.head_n.nevents - nread)) {
          ntoread = static_cast<int>(events.head_n.nevents - nread);
        }
        if (ntoread > 0) {
          m_socket.receiveBytes(
              &(events.data[nread]),
              ntoread * static_cast<int>(sizeof(TCPStreamEventNeutron)));
          nread += ntoread;
        } else {
          Poco::Thread::sleep(RECV_WAIT);
        }
      }
      if (!events.isValid()) {
        throw std::runtime_error("corrupt stream - you should reconnect");
      }

      // store the events
      saveEvents(events.data, pulseTime, events.head_n.period);
    }

  } catch (std::runtime_error &
               e) { // exception handler for generic runtime exceptions

    g_log.error() << "Caught a runtime exception." << std::endl
                  << "Exception message: " << e.what() << std::endl;
    m_isConnected = false;

    m_backgroundException = boost::make_shared<std::runtime_error>(e);

  } catch (std::invalid_argument &
               e) { // TimeSeriesProperty (and possibly some other things) can
                    // can throw these errors
    g_log.error() << "Caught an invalid argument exception." << std::endl
                  << "Exception message: " << e.what() << std::endl;
    m_isConnected = false;
    std::string newMsg(
        "Invalid argument exception thrown from the background thread: ");
    newMsg += e.what();
    m_backgroundException = boost::make_shared<std::runtime_error>(newMsg);

  } catch (...) { // Default exception handler
    g_log.error() << "Uncaught exception in ISISLiveEventDataListener network "
                     "read thread." << std::endl;
    m_isConnected = false;
    m_backgroundException = boost::shared_ptr<std::runtime_error>(
        new std::runtime_error("Unknown error in backgound thread"));
  }
}
Ejemplo n.º 8
0
bool EventRecorder::specialKey(key k, modifier m, int x, int y)
{
    if (isRecording) {
        if (k == KEY_F12) {

            char stime[256];
            Timer::getDateTimeString(stime, 256);

            char name[256];
            sprintf(name, "record.%s.dat", stime);
            ofstream out(name, ofstream::binary);
            int n = recordedEvents.size();
            out.write((char*) &n, sizeof(int));
            for (int i = 0; i < n; ++i) {
                Event e = recordedEvents[i];
                out.write((char*) &e, sizeof(Event));
            }
            out.close();
            isRecording = false;
            return true;
        } else {
            recordedEvents.push_back(Event(Event::SPECIAL, (int) m, (int) k, x, y, 0));
            saveEvents();
        }
    } else if (isPlaying) {
        return true;
    }
    if (k == KEY_F11) {
        if (recordedEvents.empty() && eventFile != NULL) {
            ifstream in(eventFile, ifstream::binary);
            int n;
            in.read((char*) &n, sizeof(int));
            for (int i = 0; i < n; ++i) {
                Event e;
                in.read((char*) &e, sizeof(Event));
                recordedEvents.push_back(e);
            }
            in.close();
            getRecorded()->saveState();
        }
        if (!recordedEvents.empty()) {
            getRecorded()->restoreState();
            lastPlayed = 0;
            savedX = -cursW - 1;
            savedY = -cursH - 1;
            isPlaying = true;
            saveVideo = (m & SHIFT) != 0;
            lastSavedEvent = -1;
            lastSavedFrame = 0;
            if ((m & CTRL) != 0 && (m & SHIFT) == 0) {
                // quit after replay
                recordedEvents.push_back(Event(0.0, 0.0, 0.0));
                recordedEvents.push_back(Event(Event::KEYBOARD, 0, 27, 0, 0, 0));
            }
        }
        return true;
    }
    if (k == KEY_F12) {
        getRecorded()->saveState();
        recordedEvents.clear();
        isRecording = true;
        return true;
    }
    return next != NULL && next->specialKey(k, m, x, y);
}