예제 #1
0
void Editor::removeBox(unsigned int boxId)
{
	if (m_boxIdToContainingCSP.find(boxId) != m_boxIdToContainingCSP.end()) {
		CSP* containingCSP = m_boxIdToContainingCSP[boxId];
		ConstrainedBox* currentBox = containingCSP->getBoxById(boxId);
		ConstrainedBox* mother = currentBox->mother();
		std::vector<unsigned int> boxesId;
		std::vector<unsigned int> relationId;
		std::vector<unsigned int> triggerId;


		CSP* boxCSP = currentBox->getCSP();

		if (boxCSP != NULL) {
			boxCSP->getAllBoxesId(boxesId);

			for (unsigned int i = 0; i < boxesId.size(); ++i) {
				removeBox(boxesId[i]);
			}
		}

		containingCSP->getAllBoxesId(boxesId);

		if (boxesId.size() == 0) {
			unsigned int motherHierarchyRelationId = mother->getHierarchyRelationId();

			if (motherHierarchyRelationId != NO_ID) {
				if (m_boxIdToContainingCSP.find(mother->getId()) != m_boxIdToContainingCSP.end()) {
					CSP* motherCSP = m_boxIdToContainingCSP[mother->getId()];
					motherCSP->removeTemporalRelation(motherHierarchyRelationId);
				}
			}
		}

		containingCSP->removeBox(boxId, relationId, triggerId);

		for (unsigned int i = 0; i < relationId.size(); ++i) {
			removeTemporalRelation(relationId[i]);
		}

		for (unsigned int i = 0; i < triggerId.size(); ++i) {
			removeTriggerPoint(triggerId[i]);
		}

		m_boxIdToContainingCSP.erase(boxId);
	}
}
예제 #2
0
unsigned int
CSPold::addBox(unsigned int boxId, int boxBeginPos, int boxLength, unsigned int motherId, int maxSceneWidth)
{

	// Vérification de la non existence de boxId
	map<unsigned int, ConstrainedTemporalEntity *>::iterator iter = (*_cedEntities).find(boxId);
	if(iter != (*_cedEntities).end())  {
		throw IllegalArgumentException();
	}

	// Création dans le solver et dans le CSP des valeurs de début et de taille de la boite
	CSPConstrainedVariable *begin = new CSPConstrainedVariable(_solver->addIntVar(1, maxSceneWidth, boxBeginPos, (int)BEGIN_VAR_TYPE),
			1, maxSceneWidth, boxBeginPos, BEGIN_VAR_TYPE);
	CSPConstrainedVariable *length = new CSPConstrainedVariable(_solver->addIntVar(10, maxSceneWidth, (int)boxLength, (int)LENGTH_VAR_TYPE),
			10, maxSceneWidth, (int)boxLength, LENGTH_VAR_TYPE);

	// Création de la boite
	ConstrainedBox *newBox = new ConstrainedBox(begin, length);

	// Création dans le solver et dans le CSP des valeurs du ControlPoint de fin de la boite
	CSPConstrainedVariable *CP2begin = new CSPConstrainedVariable(_solver->addIntVar(1, maxSceneWidth, boxBeginPos + boxLength, (int)BEGIN_VAR_TYPE),
			1, maxSceneWidth, boxBeginPos + boxLength, BEGIN_VAR_TYPE);
	CSPConstrainedVariable *CP2length = new CSPConstrainedVariable(_solver->addIntVar(0, maxSceneWidth, 0, (int)LENGTH_VAR_TYPE),
			0, maxSceneWidth, 0, LENGTH_VAR_TYPE);

	// Création et ajout dans la boite d'un CP équivalent à la boite et d'un autre à la fin
	newBox->addControlPoint(new ControlPoint(begin, length, boxId), BEGIN_CONTROL_POINT_INDEX);
	newBox->addControlPoint(new ControlPoint(CP2begin, CP2length, boxId), END_CONTROL_POINT_INDEX);

	// Ajout de la relation entre la boite et sa fin
	addAllenRelation(newBox->getLastControlPoint(), newBox, ALLEN_FINISHES, false);

	// ??
	newBox->getFirstControlPoint()->setProcessStepId(1);
	newBox->getLastControlPoint()->setProcessStepId(2);

	if (motherId != NO_ID) {
//		ConstrainedBox* mother = getBoxById(motherId);
//		newBox->setMother(mother);
//		mother->addChild(newBox);
	}

	(*_cedEntities)[boxId] = newBox;
	newBox->setId(boxId);

	//changeAllBoxMaxSceneWidth(10000);

	return newBox->getId();
}