コード例 #1
0
static void generate_exp_models2(char *baseName, int maxComp, int numbOfComp)
{
	int i;
	int j;
	ContainerRoot *expModel;
	ComponentInstance *comp;
	TypeDefinition *compType;
	hashmap_map *typDefs;
	ContainerNode *node;
	hashmap_map *nodes;
	Dictionary *dico;
	DictionaryValue *dicVal;
	char compName[32];
	int k = 0;
	int mapPos;

	expModel = open_model("../models/BaseModel.json");


	for (i = 1; i <= numbOfComp; i++) {
		ContainerNode *node = new_ContainerNode();
		node->name = malloc(4);
		sprintf(node->name, "n%d", i);
		node->typeDefinition = expModel->VT->findTypeDefsByID(expModel, "ContikiNode/0.0.1");
		node->metaData = strdup("");
		node->started = true;
		printf("Groupd %s at address %\n", expModel->VT->findGroupsByID(expModel, "group0"));
		if (expModel->VT->findGroupsByID(expModel, "group0") == 0){
			fprintf(stderr, "ERROR: The group was not found\n");	
			exit(1);
		}
		if (node->typeDefinition == 0) {
			fprintf(stderr, "Error locating typedefinition\n");
			exit(1);
		}
		node->VT->addGroups(node, expModel->VT->findGroupsByID(expModel, "group0"));

		NetworkInfo *netInfo = new_NetworkInfo();
		netInfo->name = strdup("ip");

		NetworkProperty *netProp = new_NetworkProperty();
		netProp->name = strdup("local");
		netProp->value = (char*) malloc(32);
		sprintf(netProp->value, "fe80::212:74%02x:%x:%x%02x", (unsigned int)i,(unsigned int)i, (unsigned int)i, (unsigned int)i);

		netInfo->VT->addValues(netInfo, netProp);

		node->VT->addNetworkInformation(node, netInfo);

		expModel->VT->addNodes(expModel, node);
	}
		/*
		 * Add random components to model
		 */

		for (int count = 0 ; count < 50 ; count++) {

			printf("Iteration %d\n", count);
			nodes = (hashmap_map*)expModel->nodes;
			bool found = false;
			while(!found) {
				node = (ContainerNode*)nodes->data[get_map_num(50)].data;
				printf("INFO: Looking for ContainerNode %s\n", node->VT->internalGetKey(node));
				int t = 50 / 9;
				if ( 50 % 9 != 0) {
					t++;
				}
				if (hashmap_length(node->components) < t) {
					found = true;
				}
			}

			found = false;
			int randNumb;
			int z;
			hashmap_map *n;
			n = (hashmap_map*)node->components;
			typDefs = (hashmap_map*)expModel->typeDefinitions;
			while (!found) {
				bool tmp = false;
				randNumb = get_map_num(4);
				compType = (TypeDefinition*)typDefs->data[randNumb + 2].data;
				for (z = 0; n != NULL && z < n->table_size; z++) {
					ComponentInstance *ci;
					ci = (ComponentInstance*)n->data[z].data;
					if (ci->typeDefinition == compType) {
						tmp = true;
					}
				}
				found = !tmp;
			}


			printf("INFO: Looking for TypeDefinition %s\n", compType->VT->internalGetKey(compType));

			comp = new_ComponentInstance();
			sprintf(compName, "c%d", k++);
			comp->name = strdup(compName);
			comp->started = true;
			comp->metaData = strdup("");
			comp->VT->addTypeDefinition(comp, compType);

			dico = new_Dictionary();
			dicVal = new_DictionaryValue();
			switch (randNumb) {
			case 2:
				dicVal->name = strdup("name");
				dicVal->value = strdup("Paco");
				break;
			case 3:
				dicVal->name = strdup("count");
				dicVal->value = strdup("10");
				dico->VT->addValues(dico, dicVal);
				dicVal = new_DictionaryValue();
				dicVal->name = strdup("interval");
				dicVal->value = strdup("1000");
				break;
			case 0:
			case 1:
				dicVal->name = strdup("interval");
				dicVal->value = strdup("1000");
				break;

			default:
				break;
			}
			dico->VT->addValues(dico, dicVal);
			comp->VT->addDictionary(comp, dico);

			node->VT->addComponents(node, comp);

		}

		/*
		 * Serialize model to JSON file
		 */
		sprintf(modelName, "%s_%d.json", baseName, 0);
		expModel->VT->visit(expModel, "", actionstore, NULL, false);
		delete((KMFContainer*)expModel);
		printf("INFO: %s created!\n", modelName);
}
コード例 #2
0
ファイル: mainwindow.cpp プロジェクト: Dakror/voxie
void MainWindow::create_actions()
{
    // file menu

    new_model_action = new QAction(tr("New voxel model"), this);
    connect(new_model_action, SIGNAL(triggered()), this, SLOT(new_model()));
 
    open_model_action = new QAction(tr("Open voxel model"), this);
    connect(open_model_action, SIGNAL(triggered()), this, SLOT(open_model()));

    clone_model_action = new QAction(tr("Clone voxel model"), this);
    connect(clone_model_action, SIGNAL(triggered()), this, SLOT(clone_model()));
 
    save_action = new QAction(tr("&Save"), this);
    save_action->setShortcuts(QKeySequence::Save);
    connect(save_action, SIGNAL(triggered()), this, SLOT(save()));
 
    save_as_action = new QAction(tr("Save &As..."), this);
    save_as_action->setShortcuts(QKeySequence::SaveAs);
    connect(save_as_action, SIGNAL(triggered()), this, SLOT(save_as()));
 
    exit_action = new QAction(tr("E&xit"), this);
    exit_action->setShortcuts(QKeySequence::Quit);
    exit_action->setStatusTip(tr("Exit the application"));
    connect(exit_action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
 
/*        cut_action = new QAction(tr("Cu&t"), this);
    cut_action->setShortcuts(QKeySequence::Cut);
    cut_action->setStatusTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cut_action, SIGNAL(triggered()), this, SLOT(cut()));
 
    copy_action = new QAction(tr("&Copy"), this);
    copy_action->setShortcuts(QKeySequence::Copy);
    copy_action->setStatusTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copy_action, SIGNAL(triggered()), this, SLOT(copy()));
 
    paste_action = new QAction(tr("&Paste"), this);
    paste_action->setShortcuts(QKeySequence::Paste);
    paste_action->setStatusTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(paste_action, SIGNAL(triggered()), this, SLOT(paste()));*/

    // model menu

    double_size_action = new QAction(tr("Double size"), this);
    // new_action->setShortcuts(QKeySequence::New);
    connect(double_size_action, SIGNAL(triggered()), this, 
        SLOT(double_size()));
 
    half_size_action = new QAction(tr("Half size"), this);
    // open_action->setShortcuts(QKeySequence::Open);
    connect(half_size_action, SIGNAL(triggered()), this, 
        SLOT(half_size()));
 
    optimize_action = new QAction(tr("Optimize dimensions"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(optimize_action, SIGNAL(triggered()), this,
        SLOT(optimize()));

    rotate_action = new QAction(tr("Rotate 90 degrees"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(rotate_action, SIGNAL(triggered()), this,
        SLOT(rotate()));

}
コード例 #3
0
static void generate_exp_models(char *baseName, int maxComp)
{
	int i;
	int j;
	ContainerRoot *expModel;
	ComponentInstance *comp;
	TypeDefinition *compType;
	hashmap_map *typDefs;
	ContainerNode *node;
	hashmap_map *nodes;
	Dictionary *dico;
	DictionaryValue *dicVal;
	char compName[32];
	int k = 0;
	int mapPos;


	for (i = 1; i <= NUM_OF_EXP; i++) {
		for (j = 0; j < NUM_OF_IT; j++) {
			expModel = open_model("../models/9nodes0component-compactLille.json");
			/*
			 * Add random components to model
			 */

			for (int count = 0 ; count < i ; count++) {
				nodes = (hashmap_map*)expModel->nodes;
				bool found = false;
				while(!found) {
					node = (ContainerNode*)nodes->data[get_map_num(9)].data;
					printf("INFO: Looking for ContainerNode %s\n", node->VT->internalGetKey(node));
					int t = i / 9;
					if ( i % 9 != 0) {
						t++;
					}
					if (hashmap_length(node->components) < t) {
						found = true;
					}
				}

				found = false;
				int randNumb;
				int z;
				hashmap_map *n;
				n = (hashmap_map*)node->components;
				typDefs = (hashmap_map*)expModel->typeDefinitions;
				while (!found) {
					bool tmp = false;
					randNumb = get_map_num(4);
					compType = (TypeDefinition*)typDefs->data[randNumb + 2].data;
					for (z = 0; n != NULL && z < n->table_size; z++) {
						ComponentInstance *ci;
						ci = (ComponentInstance*)n->data[z].data;
						if (ci->typeDefinition == compType) {
							tmp = true;
						}
					}
					found = !tmp;
				}


				printf("INFO: Looking for TypeDefinition %s\n", compType->VT->internalGetKey(compType));

				comp = new_ComponentInstance();
				sprintf(compName, "c%d", k++);
				comp->name = strdup(compName);
				comp->started = true;
				comp->metaData = strdup("");
				comp->VT->addTypeDefinition(comp, compType);

				dico = new_Dictionary();
				dicVal = new_DictionaryValue();
				switch (randNumb) {
				case 2:
					dicVal->name = strdup("name");
					dicVal->value = strdup("Paco");
					break;
				case 3:
					dicVal->name = strdup("count");
					dicVal->value = strdup("10");
					dico->VT->addValues(dico, dicVal);
					dicVal = new_DictionaryValue();
					dicVal->name = strdup("interval");
					dicVal->value = strdup("1000");
					break;
				case 0:
				case 1:
					dicVal->name = strdup("interval");
					dicVal->value = strdup("1000");
					break;

				default:
					break;
				}
				dico->VT->addValues(dico, dicVal);
				comp->VT->addDictionary(comp, dico);

				node->VT->addComponents(node, comp);

			}

			/*
			 * Serialize model to JSON file
			 */
			sprintf(modelName, "%s_%d_%d.json", baseName, i, j);
			expModel->VT->visit(expModel, "", actionstore, NULL, false);
			delete((KMFContainer*)expModel);
			printf("INFO: %s created!\n", modelName);
		}
	}
}