Example #1
0
void TextUI::processCommand()
{
	string choice;

	cin >> choice;
	switch(atoi(choice.c_str()))
	{
	case Load:
		loadERDiagram();
		displayMenu();
		break;
	case Save:
		saveERDiagram();
		displayMenu();
		break;
	case Add:
		addNewNode();
		displayMenu();
		break;
	case Connect:
		addConnection();
		displayMenu();
		break;
	case GetTable:
		displayComponentTable();
		displayConnectionTable();
		displayMenu();
		break;
	case SetPK:
		setPrimaryKey();
		displayMenu();
		break;
	case GetERTable:
		displayERDiagramTable();
		displayMenu();
		break;
	case Delete:
		deleteComponent();
		displayMenu();
		break;
	case Undo:
		undoCmd();
		displayMenu();
		break;
	case Redo:
		redoCmd();
		displayMenu();
		break;
	case Exit:
		exitERDiagram();
		break;
	default:
		cout << TEXT_MENU_ERRORCHOICE;
		displayMenu();
		break;
	}
}
bool UrlParser::removePath( const std::vector<std::pair<UrlComponent*, UrlComponent*> > &urlComponents,
                            const UrlComponent::Validator &validator ) {
	bool hasRemoval = false;
	for ( auto it = urlComponents.begin(); it != urlComponents.end(); ++it ) {
		if ( it->second == NULL ) {
			if ( validator.allowEmptyValue() ) {
				hasRemoval = true;
				deleteComponent( it->first );
			}
		} else {
			if ( validator.isValid( *( it->second ) ) ) {
				hasRemoval = true;
				deleteComponent( it->first );
				deleteComponent( it->second );
			}
		}
	}

	return hasRemoval;
}
bool UrlParser::removeComponent( const std::vector<UrlComponent*> &urlComponents, const UrlComponent::Validator &validator ) {
	bool hasRemoval = false;

	for ( auto it = urlComponents.begin(); it != urlComponents.end(); ++it ) {
		if ( (*it)->isDeleted() ) {
			continue;
		}

		if ( ( (*it)->hasValue() && validator.isValid( *(*it) ) ) ||
		     ( !(*it)->hasValue() && validator.allowEmptyValue() ) ) {
			hasRemoval = true;
			deleteComponent( *it );
		}
	}

	return hasRemoval;
}
Example #4
0
DM_COMPONENT *DirectoryManager::findComponent(DM_CONNECTEDCOMPONENT *connectedComponent, SYNTRO_UID *UID, char *name, char *type)
{
	DM_COMPONENT *component;

	component = connectedComponent->componentDE;
	while (component != NULL) {
		if (SyntroUtils::compareUID(UID, &(component->componentUID))) {	// found correct UID
			if ((strcmp(name, component->appName) == 0) && (strcmp(type, component->componentType) == 0))
				return component;							// found it
			//	Correct UID but mismatch on name or type. Implies a new component on same instance.
			//	Delete this old entry and carry on looking - there can't be two components on the same UID!
			deleteComponent(connectedComponent, component);
		}
		component = component->next;
	}
	return NULL;									// not there
}
Example #5
0
void Ui::setupComponentsBox()
{
    componentsBox = new QGroupBox(QString("Components Definition"));
    componentButtonsLayout = new QHBoxLayout;
    addComponentButton = new QPushButton(QString("Add..."));
    connect(addComponentButton, SIGNAL(clicked()), this, SLOT(openComponentDialog()));
    delComponentButton = new QPushButton(QString("Delete"));
    connect(delComponentButton, SIGNAL(clicked()), this, SLOT(deleteComponent()));
    componentButtonsLayout->addWidget(addComponentButton);
    componentButtonsLayout->addWidget(delComponentButton);
    componentsLayout = new QVBoxLayout;
    componentsList = new QListWidget;
    componentsList->setSelectionMode(QAbstractItemView::SingleSelection);
//    connect(componentsList, SIGNAL(itemClicked(QListWidgetItem*)), componentsList, SLOT(s))
    componentsLayout->addLayout(componentButtonsLayout);
    componentsLayout->addWidget(componentsList);
    componentsBox->setLayout(componentsLayout);
}
Example #6
0
//	針對Connector跟其他三種進行刪除
void ERModel::deleteFunction( int componentID )
{
	Component* delComponent = searchComponent(componentID);
	string deleteComponentIDSet;

	if (delComponent->getType() != PARAMETER_CONNECTOR)
	{
		deleteComponentIDSet = deleteComponent(delComponent);
	}
	else
	{
		deleteConnection(delComponent);
		deleteComponentIDSet = Toolkit::integerToString(componentID);
	}

	//	刪除完畢,通知observer更新
	notifyDeleteComplete(deleteComponentIDSet);
}
Example #7
0
void DirectoryManager::freeConnectedComponent(DM_CONNECTEDCOMPONENT *connectedComponent)
{
	if (connectedComponent == NULL || !connectedComponent->valid)
		return;												// if not set up yet

	TRACE1("Freeing connected component %s", qPrintable(SyntroUtils::displayUID(&connectedComponent->connectedComponentUID)));

	m_server->m_multicastManager.MMDeleteRegistered(&(connectedComponent->connectedComponentUID), -1);
	connectedComponent->valid = false;

	while (connectedComponent->componentDE != NULL) {
		deleteComponent(connectedComponent, connectedComponent->componentDE);
	}

	if (connectedComponent->DE != NULL) {
		free(connectedComponent->DE);
		connectedComponent->DE = NULL;
	}
}
void PropertiesManager::createEmptySelectionProperties()
{
    root->addItemsToolbar->addAction(root->actionAddRegime);
    root->actionMove_Up->setEnabled(false);
    root->actionMove_Down->setEnabled(false);
    root->actionDeleteItems->setEnabled(false);

    //component name
    QLabel *label = new QLabel("<b>Component Class</b>");
    addRow(label);
    QLineEdit *edit_name = new QLineEdit();
    edit_name->installEventFilter(&eventFilterObject);
    edit_name->setValidator(componentNameValidator);
    edit_name->setText(root->al->name);
    connect(edit_name, SIGNAL(textEdited(QString)), root, SLOT(setComponentClassName(QString)));
    addRow(tr("&Name:"),edit_name);

    //component type
    QComboBox *type = new QComboBox();
    type->addItem("neuron_body");
    type->addItem("weight_update");
    type->addItem("postsynapse");
    //type->addItem("generic_component");
    int typeVal;
    if (root->al->type == "neuron_body")
        typeVal = 0;
    if (root->al->type == "weight_update")
        typeVal = 1;
    if (root->al->type == "postsynapse")
        typeVal = 2;
    if (root->al->type == "generic_component")
        typeVal = 3;
    type->setCurrentIndex(typeVal);
    connect(type, SIGNAL(currentIndexChanged(QString)), root, SLOT(setComponentClassType(QString)));
    addRow(tr("&Component Type:"),type);

    //initial regime
    QComboBox *initial_regime = new QComboBox();
    bool match_init_r = false;
    for (int i=0; i<root->al->RegimeList.size(); i++){
        initial_regime->addItem(root->al->RegimeList[i]->name);
        if (root->al->initial_regime == root->al->RegimeList[i]){
            initial_regime->setCurrentIndex(i);
            match_init_r = true;
        }
    }
    if (!match_init_r){
        initial_regime->setCurrentIndex(-1);
    }
    connect(initial_regime, SIGNAL(currentIndexChanged(QString)), root, SLOT(setInitialRegime(QString)));
    addRow(tr("&Initial Regime:"),initial_regime);

    // add path combobox - NO LONGER USED
    /*QComboBox * path = new QComboBox;
    path->addItem("model");
    path->addItem("temp");
    path->addItem("lib");

    path->setToolTip("Store the component externally as a file (temp) or internally in the library (lib)");

    // select current path - NO LONGER USED
    if (root->al->path == "")
        root->al->path = "temp";
    if (root->al->path == "model")
        path->setCurrentIndex(0);
    else if (root->al->path == "temp")
        path->setCurrentIndex(1);
    else if (root->al->path == "lib")
        path->setCurrentIndex(2);

    // disable model path
    QModelIndex ind = path->model()->index(0,0);
    path->model()->setData(ind, QVariant(0), Qt::UserRole-1);
    addRow(tr("Path"), path);
    connect(path, SIGNAL(currentIndexChanged(QString)), root, SLOT(setPath(QString)));*/

    QPushButton * duplicate = new QPushButton("Duplicate component");
    connect(duplicate, SIGNAL(clicked()), root->main, SLOT(duplicate_component()));
    addWidget(duplicate);


    QPushButton * remove = new QPushButton("Remove component");
    connect(remove, SIGNAL(clicked()), root, SLOT(deleteComponent()));
    addWidget(remove);

}
Example #9
0
bool DirectoryManager::DMProcessDE(DM_CONNECTEDCOMPONENT *connectedComponent, char *DE, int len)
{
	int DELength;
	int entryLength;
	char *thisEntry, *nextEntry;

	int index;
	char tag[SYNTRO_MAX_TAG];
	char nonTag[SYNTRO_MAX_NONTAG];
	DM_SERVICE *service;
	DM_COMPONENT *component;								// we extract into this for lookup
	DM_COMPONENT *componentLookup;							// result of lookup
	DM_COMPONENT *previousComponent;						// for deleting components at end
	int i;
	bool changed;											// so we know if something changed

	if (DE == NULL)
		return true;
	if (len == 0)
		return true;										// means that there's no change

	TRACE1("New directory from %s", qPrintable(SyntroUtils::displayUID(&(connectedComponent->connectedComponentUID))));
	QMutexLocker locker(&m_lock);

	changed = false;
	component = connectedComponent->componentDE;
	while (component != NULL) {
		component->seenInDE = false;						// set not seen on all components
		component = component->next;
	}

	DELength = len;
	thisEntry = DE;

	while (DELength > 0) {
		entryLength = (int)strlen(thisEntry) + 1;			// find the length of this entry
		nextEntry = thisEntry + entryLength;				// this is where the next entry will start

		m_tagPtr = thisEntry;								// set pointer for tag routines
		if (!getTag(tag))
			break;
		if (strcmp(tag, DETAG_COMP) != 0)
			return false;

//	Read in endpoint component header. See if this already exists in directory

		component = (DM_COMPONENT *)calloc(1, sizeof(DM_COMPONENT));
		if (!getSimpleValue(DETAG_UID, component->UIDStr, sizeof(SYNTRO_UIDSTR)))
			goto deerr;
		if (!getSimpleValue(DETAG_APPNAME, component->appName, SYNTRO_MAX_APPNAME))
			goto deerr;
		if (!getSimpleValue(DETAG_COMPTYPE, component->componentType))
			goto deerr;
		SyntroUtils::UIDSTRtoUID(component->UIDStr, &(component->componentUID));
		if ((componentLookup = findComponent(connectedComponent, &(component->componentUID), 
							component->appName, component->componentType)) != NULL) {	// this component already exists in directory
			if(componentLookup->originalDE == NULL) {			// should never happen but just in case
				logError(QString("DirectoryManager found NULL origde when processing ") + SyntroUtils::displayUID(&(component->componentUID)));
				free(component);
				goto nextde;
			}
			if (strcmp(thisEntry, componentLookup->originalDE) == 0) {		// DE hasn't changed - can terminate processing
				free(component);
				componentLookup->seenInDE = true;			// flag as seen
				goto nextde;								// nothing more to do for this one
			}
			//	if we get here, DE has changed so we need to continue processing
			deleteComponent(connectedComponent, componentLookup);// clear down old entry
		}
		component->seenInDE = true;							// indicate this component has been seen in DE
		changed = true;

//	Now read in the service entries and add them to the service array

		index = 0;											// generates port numbers
		component->serviceCount = 0;							// clear services count
		while(1) {
			if (!getTag(tag))
				break;										// finished
			if (strcmp(tag, DETAG_COMP_END) == 0) {			// hit end of component
				break;
			}
			if (component->serviceCount == SYNTRO_MAX_SERVICESPERCOMPONENT) {
				strcpy(m_lastError, "Too many services in DE");
				goto deerr;
			}
			service = component->services + index;			// this is where the new one goes

			if (!getNonTag(nonTag))						// get the value
				goto deerr;

			if (strcmp(tag, DETAG_MSERVICE) == 0) {		// multicast service
				service->serviceType = SERVICETYPE_MULTICAST;
			} else {
				if (strcmp(tag, DETAG_ESERVICE) == 0) {
					service->serviceType = SERVICETYPE_E2E;
				} else {
					if (strcmp(tag, DETAG_NOSERVICE) == 0) {
						service->serviceType = SERVICETYPE_NOSERVICE;
					} else {
						strcpy(m_lastError, "Incorrect service type in DE");
						goto deerr;
					}
				}
			}
			if (strlen(nonTag) >= SYNTRO_MAX_SERVNAME) {
				strcpy(m_lastError, "Service name too long in DE");
				goto deerr;
			}
			strcpy(service->serviceName, nonTag);
			service->port = index++;
			service->valid = true;

//	Get closing tag - don't really need to be fussy here

			if (!getTag(tag))
				goto deerr;

			component->serviceCount++;						// accept this one and move on
			continue;

deerr:
			logError(m_lastError);
			free(component);
			goto nextde;									// give up on this and go to next
		}

		// if get here, processed component

		service = component->services;
		for (i = 0; i < component->serviceCount; i++, service++) {
			if ((component->services[i].serviceType == SERVICETYPE_E2E) || 
				(component->services[i].serviceType == SERVICETYPE_NOSERVICE)) {
				component->services[i].multicastMap = NULL;
			} else {										// need to allocate a multicast map
				component->services[i].multicastMap = m_server->m_multicastManager.MMAllocateMMap(
							&(connectedComponent->connectedComponentUID),
							&(component->componentUID), 
							component->appName,
							service->serviceName, 
							service->port);
			}
		}
		component->originalDE = (char *)malloc(strlen(thisEntry) + 1);
		strcpy(component->originalDE, thisEntry);			// record the original DE
		buildLocalDE(component);							// generate a new DE with adjusted port numbers
		m_server->m_fastUIDLookup.FULAdd(&(component->componentUID), connectedComponent->data); 
		component->sequenceID = m_sequenceID++;				// alocate new ID
		component->next = connectedComponent->componentDE;	// link in new component
		connectedComponent->componentDE = component;		// save it

nextde:
		thisEntry = nextEntry;								// set up for next entry
		DELength -= entryLength;							// and take off length of last entry
	}

//	Finally, check to see if any components missing

	component = connectedComponent->componentDE;
	previousComponent = NULL;
	while (component != NULL)
	{
		if (!component->seenInDE) {							// this component wasn't seen - delete it
			deleteComponent(connectedComponent, component);
			changed = true;
			if (previousComponent == NULL)
				component = connectedComponent->componentDE;
			else
				component = previousComponent->next;		// jump over the deleted one
		} else {											// it's fine - just move on
			previousComponent = component;
			component = component->next;
		}
	}
	if (changed)
		emit DMNewDirectory(connectedComponent->index);
	return true;
}