Example #1
0
void GUI::openDoc() {
	int i = -1;
	while ((i = table->getNext(i, LVNI_SELECTED)) != -1) {
		auto data = table->getData(i);
		if (data) {
			const string& ADC_Doc = "http://adc.sourceforge.net/ADC.html";
			const string& NMDC_Doc = "http://nmdc.sourceforge.net/NMDC.html";
			const string& UDP_Doc = "https://en.wikipedia.org/wiki/User_Datagram_Protocol";

			auto& item = *reinterpret_cast<Item*>(data);
			auto isAdc = item.protocol == Util::toT("ADC");
			auto isNmdc = item.protocol == Util::toT("NMDC");

			auto openLink = [](const string& doc) {
				::ShellExecute(0, 0, Util::toT(doc).c_str(), 0, 0, SW_SHOW);
			};

			if (isAdc) {
				openLink(ADC_Doc);
			} else if (isNmdc) {
				openLink(NMDC_Doc);
			} else {
				openLink(UDP_Doc);
			}
		}
	}
}
Example #2
0
void GUI::remove() {
	util::HoldRedraw hold(table);
	int i;
	while((i = table->getNext(-1, LVNI_SELECTED)) != -1) {
		auto data = table->getData(i);
		table->erase(i);
		if(data) {
			delete reinterpret_cast<Item*>(data);
		}
	}
}
Example #3
0
void GUI::copy() {
	tstring str;

	int i = -1;
	while((i = table->getNext(i, LVNI_SELECTED)) != -1) {
		auto data = table->getData(i);
		if(data) {
			auto& item = *reinterpret_cast<Item*>(data);
			if(!str.empty()) { str += _T("\r\n"); }
			str += item.index + _T(" [") + item.dir + _T("] ") + _T(" [") + item.protocol + _T("] ") + item.ip + _T(":") + item.port + _T(" (") + item.peer + _T("): ") + item.message;
		}
	}

	dwt::Clipboard::setData(str, window);
}
bool Foam::dlLibraryTable::open
(
    const dictionary& dict,
    const word& libsEntry,
    const TablePtr& tablePtr
)
{
    if (dict.found(libsEntry))
    {
        fileNameList libNames(dict.lookup(libsEntry));

        bool allOpened = (libNames.size() > 0);

        forAll(libNames, i)
        {
            const fileName& libName = libNames[i];

            label nEntries = 0;

            if (tablePtr)
            {
                nEntries = tablePtr->size();
            }

            bool opened = dlLibraryTable::open(libName);
            allOpened = opened && allOpened;

            if (!opened)
            {
                WarningInFunction
                    << "Could not open library " << libName
                    << endl << endl;
            }
            else if (debug && (!tablePtr || tablePtr->size() <= nEntries))
            {
                WarningInFunction
                    << "library " << libName
                    << " did not introduce any new entries"
                    << endl << endl;
            }
        }

        return allOpened;
    }
Example #5
0
void GUI::clear() {
	std::vector<Item*> toDelete;

	for(size_t i = 0, n = table->size(); i < n; ++i) {
		auto data = table->getData(i);
		if(data) {
			toDelete.push_back(reinterpret_cast<Item*>(data));
		}
	}

	table->clear();
	counter = 0;

	for(auto item: toDelete) {
		delete item;
	}

	filterW->clear();
	filter.clear();
	filterSel.clear();
	initFilter();
}
Example #6
0
LRESULT GUI::handleCustomDraw(NMLVCUSTOMDRAW& data) {
	auto item = static_cast<int>(data.nmcd.dwItemSpec);
//	auto column = data.iSubItem; // Potential per-subItem coloring

	if (data.nmcd.dwDrawStage == CDDS_PREPAINT) {
		return CDRF_NOTIFYITEMDRAW;
	}

	if ((data.nmcd.dwDrawStage & CDDS_ITEMPREPAINT) == CDDS_ITEMPREPAINT && data.dwItemType == LVCDI_ITEM && data.nmcd.lItemlParam) {

		auto rect = table->getRect(item, LVIR_BOUNDS);

		Item* it = (Item*)data.nmcd.lItemlParam;
		if (data.nmcd.hdr.hwndFrom == table->handle()) {

			if (/*(eColorFormat) &&*/ it->protocol == _T("ADC")) {
				data.clrText = RGB(255, 51, 51);
			} else if (it->protocol == _T("NMDC")) {
				data.clrText = RGB(102, 0, 204);
			} else if (it->protocol == _T("UDP")) {
				data.clrText = RGB(0, 255, 28);
			}

		}
		
		/*
		HFONT font = nullptr;
		auto ret = data.nmcd.lItemlParam;
		if (ret == CDRF_NEWFONT && font) {
			::SelectObject(data.nmcd.hdc, font);
		}
		return ret;
		*/
	}

	return CDRF_DODEFAULT;
}
bool AddConstraintHandler::handleURI(URI& uri)
{
    if (uri.action != "add_constraint")
        return false;

    wxString type = uri.getParam("type");    // pk, fk, check, unique
    Table* t = extractMetadataItemFromURI<Table>(uri);
    wxWindow* w = getParentWindow(uri);
    if (!t || !w)
        return true;

    // Find first available constraint name:
    DatabasePtr db = t->getDatabase();
    wxString prefix = type + "_" + t->getName_();
    wxString stmt(
        "select rdb$constraint_name from rdb$relation_constraints "
        "where rdb$relation_name = '" + t->getName_() +
        "' and rdb$constraint_name starting with '" + prefix +
        "' order by 1");
    wxString default_value;
    wxArrayString constraintNames(db->loadIdentifiers(stmt));
    for (int i = 0; ; ++i)
    {
        default_value = prefix + wxString::Format("_%d", i);
        if (constraintNames.Index(default_value, false) == wxNOT_FOUND)
            break;
    }

    wxString cname = ::wxGetTextFromUser(_("Enter constraint name"),
        _("Adding new table constraint"), default_value, w);
    if (cname.IsEmpty())    // cancel
        return true;

    wxString sql = "alter table " + t->getQuotedName() +
            "\nadd constraint " + Identifier::userString(cname);

    if (type == "PK")
    {
        wxString columnlist = selectRelationColumns(t, w);
        if (columnlist.IsEmpty())   // cancel
            return true;
        sql += "\nprimary key (" + columnlist + ")";
    }
    else if (type == "FK")
    {
        wxString columnlist = selectRelationColumns(t, w);
        if (columnlist == "")
            return true;
        TablePtr ref = selectTable(t->getDatabase(), w);
        if (!ref)
            return true;
        wxString refcolumnlist = selectRelationColumns(ref.get(), w);
        if (refcolumnlist == "")
            return true;
        sql += "\nforeign key (" + columnlist + ") \nreferences " + ref->getQuotedName()
            + " (" + refcolumnlist + ")";
        wxString action = selectAction(_("update"), w);
        if (action == "CANCEL")
            return true;
        else if (action != "RESTRICT")
            sql += "\non update " + action + " ";

        action = selectAction(_("delete"), w);
        if (action == "CANCEL")
            return true;
        else if (action != "RESTRICT")
            sql += "\non delete " + action + " ";
    }
    else if (type == "CHK")
    {
        wxString source;
        if (!GetMultilineTextFromUser(w, _("Enter check condition"), source))
            return true;
        sql += "\ncheck (" + source + ")";
    }
    else if (type == "UNQ")
    {
        wxString columnlist = selectRelationColumns(t, w);
        if (columnlist.IsEmpty())   // cancel
            return true;
        sql += "\nunique (" + columnlist + ")";
    }
    else
    {
        ::wxMessageBox(_("Unknown constraint type"), _("Error."), wxOK | wxICON_ERROR);
        return true;
    }

    execSql(w, "", db, sql, true);  // true = commit + close at once
    return true;
}
Example #8
0
void RecordManager::commit() {
    if (BufferManager::status == "DISABLE") {}
    else {
        //BufferManager::clearBlocks();
        cout << "cm: " << tables.size() << endl;
        for (int i = 0; i < tables.size(); i++) {
            TablePtr tPtr = TablePtr(new Table(tables[i]));
            //tPtr->printBlocks();
            if (tPtr->blankTable()) break;
            cout << "ds: " << tables[i].tableName << endl;
            TableRowPtr lastRowPtr = tPtr->getTail();
            cout << "ls: " << lastRowPtr->getAddr().getOffset() << endl;
            //queue<TableRowPtr> & bQueue = iter->second;
            while (!tPtr->noBlank()) {
                TableRowPtr rPtr = tPtr->getBlankRow();
                cout << "tr: " << rPtr->getAddr().getOffset();
                tPtr->popBlank();
                //while (!lastRowPtr->isBlank()) lastRowPtr = tPtr->getPrevious(rPtr);
                cout << " ls: " << lastRowPtr->getAddr().getOffset() << endl;
                tPtr->fillBlank(rPtr, lastRowPtr->getValues());
                lastRowPtr = tPtr->getPrevious(lastRowPtr);
            }
            cout << "[]" << endl;
            tPtr->printBlocks();
            tPtr->notifyCleanup();
            //tPtr->printBlocks();
            cout << "last: " << lastRowPtr->getAddr().getOffset() << endl;
            tPtr->notifyTruncate(lastRowPtr->getAddr());
        }
    }
}
Example #9
0
	//--------------------------------------------------------------
	void ObjectsThread::processCloud()
	{
		PCPtr cloud;
		{
			inCloudMutex.lock();
			cloud = PCPtr(new PC(*inCloud));
			inCloud.reset();
			inCloudMutex.unlock();
		}

		// Updating temporal detections
		for (list<TrackedCloudPtr>::iterator iter = trackedClouds.begin(); iter != trackedClouds.end(); iter++) {			
			if((*iter)->hasObject())
			{
				PCPolyhedron* polyhedron = dynamic_cast<PCPolyhedron*>((*iter)->getTrackedObject().get());
				if (polyhedron != NULL)
				{
					// Está dentro del frustum si todos sus vértices lo están
					(*iter)->setInViewField(Frustum::IsInFrustum(polyhedron->getVertexs()));
				}
			}
			if(!(*iter)->hasObject() || (*iter)->isInViewField())
			{
				(*iter)->addCounter(-1);
			}
		}

		int size = trackedClouds.size();
		trackedClouds.remove_if(countIsLessThanZero);
		int dif = size - trackedClouds.size(); 
		
		if(cloud->empty())
		{
			updateDetectedObjects();
			return;
		}

		list<TrackedCloudPtr> newClouds;
		int debugCounter = 0;

		{
				setObjectsThreadStatus("Detecting clusters...");
				saveCloud("rawClusters.pcd", *cloud);
				std::vector<pcl::PointIndices> clusterIndices =
				findClusters(cloud, Constants::OBJECT_CLUSTER_TOLERANCE(), Constants::OBJECT_CLUSTER_MIN_SIZE());

			for (std::vector<pcl::PointIndices>::const_iterator it = clusterIndices.begin (); it != clusterIndices.end (); ++it)
			{
				PCPtr cloudCluster = getCloudFromIndices(cloud, *it);

				gModel->tableMutex.lock();
				TablePtr table = gModel->getTable();
				gModel->tableMutex.unlock();
				saveCloud("objectsCluster" + ofToString(debugCounter) + ".pcd", *cloudCluster);
				
				if(table->isOnTable(cloudCluster))
					newClouds.push_back(TrackedCloudPtr (new TrackedCloud(cloudCluster,false)));
				else
					newClouds.push_back(TrackedCloudPtr (new TrackedCloud(cloudCluster,true)));

				debugCounter++;
			}
		}

		// Look into the new clouds for the best fit
		list<TrackedCloudPtr> cloudsToMatch;
		list<TrackedCloudPtr> cloudsToAdd;

		debugCounter = 0;
		int maxIter = 10;
		setObjectsThreadStatus("Matching clusters with existing ones...");
		do
		{
			for (list<TrackedCloudPtr>::iterator iter = newClouds.begin(); iter != newClouds.end(); iter++)
			{
				//saveCloudAsFile("clusterInTable" + ofToString(debugCounter) + ".pcd", *(*iter)->getTrackedCloud());
				TrackedCloudPtr removedCloud;
				bool removed = false;
				bool fitted = findBestFit(*iter, removedCloud, removed);

				if (removed)
					cloudsToMatch.push_back(removedCloud);	// Push back the old cloud to try again
				if (!fitted)
					cloudsToAdd.push_back(*iter);			// No matching cloud, this will be a new object
				debugCounter++;
			}
			newClouds = cloudsToMatch;
			cloudsToMatch.clear();
			maxIter--;
		}
		while (newClouds.size() > 0 && maxIter > 0);

		// Effectuate the update of the tracked cloud with the new ones
		setObjectsThreadStatus("Update existing and new data...");
		updateDetectedObjects();

		trackedClouds.insert(trackedClouds.end(), cloudsToAdd.begin(), cloudsToAdd.end());
	}
Example #10
0
void GUI::create() {
	if(window) {
		window->setFocus();
		return;
	}

	Config::setConfig("Dialog", true);
	/*
	auto setBoolCfg = [&] (string setting, CheckBoxPtr enable) {
		if(enable) {
			Config::setConfig(setting, enable);
	}

	setBoolCfg("", eUserFilter);
	setCfg("", eHubFilter);
	setCfg("", eSearchFilter);
	setCfg("", eProtoFilter);
	setCfg("", eFileLogging);
	*/

	Application::init();

	{
		Window::Seed seed(_T(PLUGIN_NAME));
		seed.location.size.x = 1200;
		seed.location.size.y = 800;

		window = new Window();
		window->create(seed);

		auto iconPath = Util::toT(Config::getInstallPath() + "DevPlugin.ico");
		try {
			window->setSmallIcon(new dwt::Icon(iconPath, dwt::Point(16, 16)));
			window->setLargeIcon(new dwt::Icon(iconPath, dwt::Point(32, 32)));
		} catch(const dwt::DWTException&) { }

		window->onClosing([]() -> bool {
			window = nullptr;
			Application::uninit();
			if(!unloading) { Config::setConfig("Dialog", false); }
			return true;
		});
		window->onDestroy([this] { clear(); });
	}

	auto grid = window->addChild(Grid::Seed(3, 1));
	grid->column(0).mode = GridInfo::FILL;
	grid->row(0).mode = GridInfo::FILL;
	grid->row(0).align = GridInfo::STRETCH;
	grid->setSpacing(8);

	{
		Table::Seed seed;
		seed.style |= WS_BORDER | LVS_SHOWSELALWAYS;
		seed.lvStyle = LVS_EX_DOUBLEBUFFER | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP;
		table = grid->addChild(seed);

		std::vector<Column> columns;
		columns.emplace_back(_T("#"), 50);
		columns.emplace_back(_T("Dir"), 50);
		columns.emplace_back(_T("Protocol"), 60);
		columns.emplace_back(_T("IP"), 100);
		columns.emplace_back(_T("Port"), 50);
		columns.emplace_back(_T("Peer info"), 200);
		columns.emplace_back(_T("Message"));
		table->setColumns(columns);
		table->onSized([this](const SizedEvent& e) { table->setColumnWidth(6, e.size.x - 50 - 50 - 60 - 100 - 50 - 200 - 20); });

		table->onContextMenu([this](const ScreenCoordinate& pt) -> bool {
			auto menu = window->addChild(Menu::Seed());
			auto hasSel = table->hasSelected();
			menu->appendItem(_T("Copy selected messages"), [=] { copy(); }, nullptr, hasSel);
			menu->appendItem(_T("Remove selected messages"), [=] { remove(); }, nullptr, hasSel);
			menu->appendSeparator();
			menu->appendItem(_T("Select all"), [] { table->selectAll(); }, nullptr, !table->empty());

			menu->appendSeparator();
			menu->appendItem(_T("Open protocol documentation"), [=] { openDoc(); }, nullptr, hasSel);

			menu->open(pt.x() == -1 || pt.y() == -1 ? table->getContextMenuPos() : pt);
			
			return true;
		});

		table->onCustomDraw([this](NMLVCUSTOMDRAW& data) { return GUI::handleCustomDraw(data); });
	}

	{
		auto cur = grid->addChild(Grid::Seed(1, 5));
		cur->setSpacing(30);

		auto hubMessagesW = cur->addChild(CheckBox::Seed(_T("Add hub messages")));
		hubMessagesW->setChecked(true);
		hubMessagesW->onClicked([this, hubMessagesW] { hubMessages = hubMessagesW->getChecked(); });

		auto userMessagesW = cur->addChild(CheckBox::Seed(_T("Add user messages")));
		userMessagesW->setChecked(true);
		userMessagesW->onClicked([this, userMessagesW] { userMessages = userMessagesW->getChecked(); });

		{
			ComboBox::Seed seed;
			seed.style |= CBS_DROPDOWNLIST | CBS_SORT;
			filterW = cur->addChild(seed);
			initFilter();
			filterW->onSelectionChanged([this] {
				auto str = filterW->getText();
				if(str == noFilter) {
					filterSel.clear();
				} else {
					filterSel = move(str);
				}
			});
		}

		{
			auto cur2 = cur->addChild(GroupBox::Seed(_T("Regex filter")))->addChild(Grid::Seed(1, 2));
			cur2->column(0).size = 250;

			TextBox::Seed seed;
			seed.style |= ES_AUTOHSCROLL;
			auto box = cur2->addChild(seed);

			Button::Seed bs(_T("Apply"));
			bs.padding.x += 8;
			cur2->addChild(bs)->onClicked([this, box] {
				regex = "";
				try {
					regex.assign(Util::fromT(box->getText()));
				} catch(const std::runtime_error&) {
					dwt::MessageBox(window).show(_T("Invalid regular expression"), window->getText(),
						dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONEXCLAMATION);
				}
			});
		}

		{
			auto cur2 = cur->addChild(GroupBox::Seed(_T("Log to a file")))->addChild(Grid::Seed(1, 2));
			cur2->column(0).size = 250;

			log = Config::getConfig("Log");

			TextBox::Seed seed(Util::toT(log));
			seed.style |= ES_AUTOHSCROLL;
			auto box = cur2->addChild(seed);
			box->onUpdated([this, box] { log = Util::fromT(box->getText()); Config::setConfig("Log", log); });

			Button::Seed bs(_T("Browse"));
			bs.padding.x += 8;
			cur2->addChild(bs)->onClicked([this, box] {
				auto file = Util::toT(log);
				if(SaveDialog(window).open(file)) {
					log = Util::fromT(file);
					Config::setConfig("Log", log);
					box->setText(file);
				}
			});
		}
	}

	{
		auto cur = grid->addChild(Grid::Seed(1, 5));
		cur->column(4).mode = GridInfo::FILL;
		cur->column(4).align = GridInfo::BOTTOM_RIGHT;
		cur->setSpacing(30);

		Button::Seed bs;
		bs.padding.x += 20;

		bs.caption = _T("Copy selected messages");
		cur->addChild(bs)->onClicked([this] { copy(); });

		auto scrollW = cur->addChild(CheckBox::Seed(_T("Auto-scroll")));
		scrollW->setChecked(true);
		scrollW->onClicked([this, scrollW] { scroll = scrollW->getChecked(); });

		bs.caption = _T("Clear the list");
		cur->addChild(bs)->onClicked([this] { clear(); });

		auto onTop = cur->addChild(CheckBox::Seed(_T("Keep this window on top")));
		onTop->onClicked([onTop] { window->setZOrder(onTop->getChecked() ? HWND_TOPMOST : HWND_NOTOPMOST); });

		bs.caption = _T("Close");
		bs.style |= BS_DEFPUSHBUTTON;
		bs.padding.x += 20;
		cur->addChild(bs)->onClicked([] { window->close(true); });
	}

	grid->resize(window->getClientSize());
	window->onSized([grid](const SizedEvent& e) { grid->resize(e.size); });

	table->setFocus();

	window->setTimer([this]() -> bool { timer(); return true; }, 500);
}
Example #11
0
void GUI::timer() {
	int pos = -1;

	FILE* f = nullptr;
	if(!log.empty()) {
		f = fopen(log.c_str(), "a");
	}

	std::unique_ptr<Message> messagePtr;
	while(messages.pop(messagePtr)) {
		auto& message = *messagePtr.get();


		//TODO Handle filtering here
		/*
		DFilter filt(message);
		*/
		if(!(message.hubOrUser ? hubMessages : userMessages)) {
			continue;
		}

		auto ip = Util::toT(message.ip);
		if(!filterSel.empty() && ip != filterSel) {
			continue;
		}

		if(!regex.empty()) {
			try {
				if(!boost::regex_search(message.message, regex)) {
					continue;
				}
			} catch(const std::runtime_error&) {
				// most likely a stack overflow, ignore...
				continue;
			}
		}

		if(f) {
			fprintf(f, "%u [%s] [%s] %s:%u (%s): %s\n", counter, message.sending ? "Out" : "In",
				message.protocol.c_str(), message.ip.c_str(), message.port, message.peer.c_str(), message.message.c_str());
		}

		auto item = new Item;
		item->index = Util::toT(boost::lexical_cast<string>(counter));
		item->dir = message.sending ? _T("Out") : _T("In");
		item->protocol = Util::toT(message.protocol);
		item->ip = move(ip);
		item->port = Util::toT(boost::lexical_cast<string>(message.port));
		item->peer = Util::toT(message.peer);
		item->message = Util::toT(message.message);

		std::vector<tstring> row;
		row.push_back(item->index);
		row.push_back(item->dir);
		row.push_back(item->protocol);
		row.push_back(item->ip);
		row.push_back(item->port);
		row.push_back(item->peer);
		row.push_back(item->message);
		pos = table->insert(row, reinterpret_cast<LPARAM>(item));

		++counter;

		if(filter.find(item->ip) == filter.end()) {
			filterW->addValue(*filter.insert(item->ip).first);
		}
	}

	if(f) {
		fclose(f);
	}

	if(scroll && pos != -1) { // make sure something was added
		table->ensureVisible(pos);
	}
}