Пример #1
0
int ERModel::addConnection( int componentID, int sourceNodeID, int destinationNodeID, string text )
{
	Component* sourceNode = searchComponent(sourceNodeID);
	Component* destinationNode = searchComponent(destinationNodeID);
	Component* newConnection;
	ComponentFactory* componentFactory = new ComponentFactory();

	if (sourceNode == NULL || destinationNode == NULL )
		return PARAMETER_ISERROR;

	_isModify = true;

	if (checkConnectionState(sourceNode, destinationNode) == TEXT_CONNECTION_CANCONNECT)
	{
		newConnection = static_cast<Component*>(componentFactory->creatComponent(componentID, PARAMETER_CONNECTOR, text, PARAMETER_TEXTUI_COORDINATES, PARAMETER_TEXTUI_COORDINATES));
		_components.push_back(newConnection);

		static_cast<Connector*>(newConnection)->setConnectedNode(sourceNode, destinationNode);
		_connections.push_back(newConnection);

		connectionSetting(sourceNode, destinationNode, text);
	}
	else
		return PARAMETER_ISERROR;
	delete componentFactory;

	return newConnection->getID();
}
Пример #2
0
void TextUI::addConnection()
{
	int firstComponentID;
	int secondComponentID;
	bool checkCardinality;
	string cardinality = PARAMETER_NULL;

	if (_presentationModel->getComponentTableSize() > PARAMETER_ZEROCOMPONENT)
	{
		// 第一個Component
		cout << TEXT_CONNECTION_FIRSTNODE;
		firstComponentID = atoi(searchComponent(PARAMETER_ALL).c_str());

		// 第二個Component
		cout << TEXT_CONNECTION_SECONDNODE;
		secondComponentID = atoi(searchComponent(PARAMETER_ALL).c_str());

		// 如果是Relationship跟Entity互相連接,輸入Cardinality
		if (_presentationModel->checkSetCardinality(firstComponentID, secondComponentID))
			cardinality = chooseCardinality();

		// 如果要connection的兩個Component有問題,則回傳問題字串
		cout << _presentationModel->addConnectionCmd(firstComponentID, secondComponentID, cardinality) << endl;

		cout << _presentationModel->displayConnectionTable_TextUI();
	}
	else
		cout << TEXT_CONNECTION_NOCOMPONENT << endl;
	
}
Пример #3
0
void ERModel::reBuildPrimaryKeyFromAttribute( int attributeID, int entityID )
{
	NodeAttribute* attributeNode = static_cast<NodeAttribute*>(searchComponent(attributeID));
	NodeEntity* entityNode = static_cast<NodeEntity*>(searchComponent(entityID));

	attributeNode->setIsPrimaryKey(true);
	entityNode->setPrimaryKey(attributeID);
}
Пример #4
0
//	The method provide to textUI to check whether set cardinality or not.
bool ERModel::checkSetCardinality( int sourceNodeID, int destinationNodeID )
{
	Component* sourceNode = searchComponent(sourceNodeID);
	Component* desinationNode = searchComponent(destinationNodeID);

	if((sourceNode->getType() == PARAMETER_ENTITY && desinationNode->getType() == PARAMETER_RELATIONSHIP) || 
		(sourceNode->getType() == PARAMETER_RELATIONSHIP && desinationNode->getType() == PARAMETER_ENTITY))
		return true;
	else
		return false;
}
Пример #5
0
//	刪除Connector
void ERModel::deleteConnection( Component* delComponent )
{
	Connector* delConnector = static_cast<Connector*>(delComponent);
	Component* sourceNode = searchComponent(delConnector->getSourceNodeID());
	Component* destinationNode = searchComponent(delConnector->getDestinationNodeID());

	sourceNode->deleteConnectedComponent(delConnector->getDestinationNodeID());
	destinationNode->deleteConnectedComponent(delConnector->getSourceNodeID());

	deleteTableSet(delComponent->getID(), _components, PARAMETER_COMPONENTSTABLE);
	deleteTableSet(delComponent->getID(), _connections, PARAMETER_CONNECTIONSTABLE);
}
Пример #6
0
//	搜尋與searchID有關係的Component,並回傳該集合
vector<Component*> ERModel::searchRelatedComponent( int searchID )
{
	vector<Component*> resultSet;

	for (int i = 0; i < _connections.size(); i++)
	{
		if (static_cast<Connector*>(_connections[i])->getSourceNodeID() == searchID)
			resultSet.push_back(searchComponent(static_cast<Connector*>(_connections[i])->getDestinationNodeID()));
		else if(static_cast<Connector*>(_connections[i])->getDestinationNodeID() == searchID)
			resultSet.push_back(searchComponent(static_cast<Connector*>(_connections[i])->getSourceNodeID()));
	}

	return resultSet;
}
Пример #7
0
void ERModel::setPrimaryKey( int entityID, vector<int> primaryKeys )
{
	NodeEntity* entityNode = static_cast<NodeEntity*>(searchComponent(entityID));
	Component* attributeNode;

	_isModify = true;

	for( int i = 0; i < primaryKeys.size(); i++)
	{
		attributeNode = searchComponent(primaryKeys[i]);
		static_cast<NodeAttribute*>(attributeNode)->setIsPrimaryKey(true);
		entityNode->setPrimaryKey(attributeNode->getID());
	}
}
Пример #8
0
string ERModel::searchAttributeOfEntity( int entityID )
{
	string attributeOfEntityDataList;
	Component* specificEntityNode = searchComponent(entityID);

	return getComponentDataList(PARAMETER_ATTRIBUTE, specificEntityNode->getConnections());
}
Пример #9
0
// 提供deleteGroup將componentIDSet的Connector抽出來,放到最前面
vector<int> ERModel::arrangeAdvanceDelete( vector<int> componentIDSet )
{
	vector<int> resultSet;
	vector<int> nodeIDSet;
	vector<int> attributeNodeIDSet;

	// 區分Connector與其他Node(Attribute, Entity, Relationship)
	for (int i = 0; i < componentIDSet.size(); i++)
	{
		Component* targetComponent = searchComponent(componentIDSet[i]);
		if (targetComponent->getType() == PARAMETER_CONNECTOR)					// 先放入Connector
			resultSet.push_back(componentIDSet[i]);
		else if(targetComponent->getType() == PARAMETER_ATTRIBUTE)				// 再放入Attribute
			attributeNodeIDSet.push_back(componentIDSet[i]);
		else																	// 把Entity, Relationship與Attribute跟Connector分離
			nodeIDSet.push_back(componentIDSet[i]);
	}

	// 合併
	for (int i = 0; i < attributeNodeIDSet.size(); i++)
		resultSet.push_back(attributeNodeIDSet[i]);
	for (int i = 0; i < nodeIDSet.size(); i++)
		resultSet.push_back(nodeIDSet[i]);

	return resultSet;
}
Пример #10
0
vector<int> ERModel::getTargetPosition( int targetNodeID )
{
	Component* targetNode = searchComponent(targetNodeID);
	vector<int> positionSet;

	positionSet.push_back(targetNode->getSx());
	positionSet.push_back(targetNode->getSy());

	return positionSet;
}
Пример #11
0
void ERModel::cloneItemIntoClipboard( vector<int> targetNodeIDSet )
{
	Component* targetNode;
	for (int i = 0; i < targetNodeIDSet.size(); i++)
	{
		targetNode = searchComponent(targetNodeIDSet[i]);
		Component* cloneNode = targetNode->deepClone();
		_clipboard.push_back(cloneNode);
	}
}
Пример #12
0
int ERModel::addCloneConnection( Component* cloneConnector )
{
	Connector* tempCloneConnector = static_cast<Connector*>(cloneConnector);

	int newSourceID = retrieveNewCloneID(tempCloneConnector->getSourceNodeID());
	int newDestinationID = retrieveNewCloneID(tempCloneConnector->getDestinationNodeID());

	vector<pair<int, bool>> changePrimaryKey;

	if (newSourceID != PARAMETER_NOTFINDID && newDestinationID != PARAMETER_NOTFINDID)
	{
		Component* newSourceNode = searchComponent(newSourceID);
		Component* newDestinationNode = searchComponent(newDestinationID);

		// 如果以前的Attribute是PK的話,對Entity及Attribute進行修正
		if (newSourceNode->getType() == PARAMETER_ATTRIBUTE)
			changePrimaryKey = reBuildPrimaryKey(searchComponent(tempCloneConnector->getSourceNodeID()), newDestinationID, newSourceID);
		else if (newDestinationNode->getType() == PARAMETER_ATTRIBUTE)
			changePrimaryKey = reBuildPrimaryKey(searchComponent(tempCloneConnector->getDestinationNodeID()), newSourceID, newDestinationID);

		// 對clone的ComponentID做修正
		tempCloneConnector->setID(_componentID);
		// ComponentID往後加
		_componentID++;
		// 設定兩個Clone的Component重新Connect
		connectionSetting(newSourceNode, newDestinationNode, tempCloneConnector->getText());
		// Connector設定新的Source及Destination
		tempCloneConnector->setSourceNode(newSourceNode);
		tempCloneConnector->setDestinationNode(newDestinationNode);

		_components.push_back(cloneConnector);
		_connections.push_back(tempCloneConnector);

		notifyNewConnection(tempCloneConnector->getID(), tempCloneConnector->getSourceNodeID(), tempCloneConnector->getDestinationNodeID(), tempCloneConnector->getText(), changePrimaryKey);

		return cloneConnector->getID();
	}

	return PARAMETER_ISERROR;
}
Пример #13
0
bool ERModel::checkOneToOne()
{
	NodeEntity* sourceEntity;
	NodeEntity* destinationEntity;
	vector<Component*> relationshipNode = searchSpecificTypeComponentSet(PARAMETER_RELATIONSHIP, _components);

	// entityCardinalitySet是透過relationship相連的兩個entity的集合,格式為(entity, cardinality).
	vector<pair<int,string>> entityCardinalitySet;

	for(int i = 0; i < relationshipNode.size(); i++){
		entityCardinalitySet = static_cast<NodeRelationship*>(relationshipNode[i])->getEntityCardinality();
		if (entityCardinalitySet.size() >= PARAMETER_RELATIONSHIPLOWERBOUND)								// 檢查relationship至少連到兩個entity.
			if (entityCardinalitySet[PARAMETER_FIRSTENTITY].second == "1" && entityCardinalitySet[PARAMETER_SECONDENTITY].second == "1")				// One to one
			{
				sourceEntity = static_cast<NodeEntity*>(searchComponent(entityCardinalitySet[PARAMETER_FIRSTENTITY].first));
				destinationEntity = static_cast<NodeEntity*>(searchComponent(entityCardinalitySet[PARAMETER_SECONDENTITY].first));
				if (sourceEntity->getPrimaryKey().size() != 0 && destinationEntity->getPrimaryKey().size() != 0 )
					return true;
			}
	}
	return false;
}
Пример #14
0
bool ERModel::changePrimaryKey( int targetNodeID, bool isPrimaryKey )
{
	Component* targetNode = searchComponent(targetNodeID);
	if (static_cast<NodeAttribute*>(targetNode)->getIsConnectedEntity())
		static_cast<NodeAttribute*>(targetNode)->setIsPrimaryKey(isPrimaryKey);
	else
		return false;

	// Attribute如果有Connect的話,一定是跟Entity並且只有一個,所以當Attribute的PK變化的時候,Entity的PK也會改變
	if (targetNode->getConnections().size() != PARAMETER_ZEROCOMPONENT)
	{
		int relatedEntityID = targetNode->getConnections()[0]->getID();
		NodeEntity* relatedEntity = static_cast<NodeEntity*>(searchComponent(relatedEntityID));

		if (isPrimaryKey)
			relatedEntity->setPrimaryKey(targetNode->getID());
		else
			relatedEntity->deleteKeys(targetNodeID);
	}

	notifyPrimaryKeyChanged(targetNodeID, isPrimaryKey);

	return true;
}
Пример #15
0
void ERModel::setForeignKey()
{
	vector<Component*> relationshipSet = searchSpecificTypeComponentSet(PARAMETER_RELATIONSHIP, _components);
	vector<int> oneToOneEntityID;	// It store two entity ID which two entity is one to one relationship.
	NodeEntity* setFKEntityNodeFirst;
	NodeEntity* setFKEntityNodeSecond;

	for(int i = 0; i < relationshipSet.size(); i++)
	{
		oneToOneEntityID = oneToOne(static_cast<NodeRelationship*>(relationshipSet[i]));
		// Two entity set the other one as Foreign Key.
		if (!oneToOneEntityID.empty())
		{
			setFKEntityNodeFirst = static_cast<NodeEntity*>(searchComponent(oneToOneEntityID[0]));
 			setFKEntityNodeSecond = static_cast<NodeEntity*>(searchComponent(oneToOneEntityID[1]));

			setFKEntityNodeFirst->setForeignKey(oneToOneEntityID[1]);
 			setFKEntityNodeSecond->setForeignKey(oneToOneEntityID[0]);
			
			setFKEntityNodeFirst->setIsShowForeignKeyinERTable(true);
			setFKEntityNodeSecond->setIsShowForeignKeyinERTable(false);
		}
	}
}
Пример #16
0
void ERModel::notifyTextChanged( int targetNodeID, string editedText )
{
	Component* connectorComponent = searchComponent(targetNodeID);
	if (connectorComponent->getType() == PARAMETER_CONNECTOR)
	{
		int sourceNodeID = static_cast<Connector*>(connectorComponent)->getSourceNodeID();
		int destinationNodeID = static_cast<Connector*>(connectorComponent)->getDestinationNodeID();
		if (checkSetCardinality(sourceNodeID, destinationNodeID))
		{
			if (editedText != "1" && editedText != "N")
				editedText = "1";
		}
		else
			editedText = "";
	}

	Subject::notifyTextChanged(targetNodeID, editedText);
}
Пример #17
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);
}
Пример #18
0
std::vector<Component> associate(cv::Mat const &depth_map, int threshold)
{
    Expander expander(depth_map.rows, depth_map.cols);
    cv::Mat mask = cv::Mat::zeros(depth_map.rows, depth_map.cols, cv::DataType<bool>::type);
    std::vector<Component> components;
    for(int i = 0; i < depth_map.rows; i++)
    {
        for(int j = 0; j < depth_map.cols; j++)
        {
            if (mask.data[i*depth_map.cols + j] == 0)
            {
                mask.data[i*depth_map.cols + j] = 1;
                Component tmp = searchComponent(Point(i, j), depth_map, mask, expander, threshold);
                if (tmp.points.size() > 5) components.push_back(tmp);
            }
        }
    }
    return components;
}
Пример #19
0
string ERModel::searchForeignKey( int foreignKeyEntityID )
{
	Component* foreignKeyEntity = searchComponent(foreignKeyEntityID);
	vector<Component*> attributeSet = searchSpecificTypeComponentSet(PARAMETER_ATTRIBUTE, foreignKeyEntity->getConnections());
	string isFKString;

	for(int i = 0; i < attributeSet.size(); i++)
	{
		if (static_cast<NodeAttribute*>(attributeSet[i])->getIsPrimaryKey())
			isFKString += attributeSet[i]->getText() + TEXT_COMMASPACE;
	}

	// 刪除最後一個", "並將格式放入string中
	if (isFKString != PARAMETER_NULL)
	{
		isFKString = isFKString.substr(PARAMETER_STRINGBEGIN, isFKString.size() - PARAMETER_ADJUSTSTRINGSIZE);
		isFKString = TEXT_GETERDIAGRAM_FK + isFKString + TEXT_GETERDIAGRAM_ENDKEY;
	}
	return isFKString;
}
Пример #20
0
//	The method provides to textUI to get connection error message.
string ERModel::getCheckConnectionStateMessage( int sourceNodeID, int destinationNodeID )
{
	Component* sourceNode = searchComponent(sourceNodeID);
	Component* desinationNode = searchComponent(destinationNodeID);
	return checkConnectionState(sourceNode, desinationNode);
}
Пример #21
0
void ERModel::setInitialPosition( int targetNodeID, int initialSx, int initialSy )
{
	Component* movedComponent = searchComponent(targetNodeID);
	movedComponent->setSx(initialSx);
	movedComponent->setSy(initialSy);
}
Пример #22
0
bool ERModel::searchEntityConnection( int entityID, int targetNodeID, string targetType)
{
	Component* entityNode = searchComponent(entityID);
	
	return searchComponentConnection(targetNodeID, targetType, entityNode->getConnections());
}
Пример #23
0
void ERModel::changeText( int targetNodeID, string editedText )
{
	searchComponent(targetNodeID)->setText(editedText);
}
Пример #24
0
bool ERModel::getTargetAttributeIsPrimaryKey( int targetNodeID )
{
	NodeAttribute* targetAttribute = static_cast<NodeAttribute*>(searchComponent(targetNodeID));

	return targetAttribute->getIsPrimaryKey();
}
Пример #25
0
void Robot::decodeAction(){
	/*
	switch(action->getAction()){
		case CENTER_SELF:
		
			std::cout << std::endl << "Action: " <<action->getActionName() << std::endl;
			switch (getType())
			{
				case MOBILE:
					Component *chasis;
					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 0);
						chasis->stablishValueLeaf("motor1", 0, 0);
						chasis->stablishValueLeaf("motor2", 0, 0);
						printHierarchy();
					}
					break;
				case HUMANOID:
					Component *right_arm;
					Component *left_arm;
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 512, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 512, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					printHierarchy();
					break;
			}

			break;
	}
	*/
	switch(getType()){
		case MOBILE:
			Component *chasis;
			switch (action->getAction())
			{
				case CENTER_SELF:
					
					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 0);
						chasis->stablishValueLeaf("motor1", 0, 0);
						chasis->stablishValueLeaf("motor2", 0, 0);
						//printHierarchy();
					}
					break;
				case MOVEMENT_UP:

					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 512);
						chasis->stablishValueLeaf("motor1", 0, 1535);
						chasis->stablishValueLeaf("motor2", 0, 512);
						//printHierarchy();
					}
					break;
				case MOVEMENT_DOWN:
					
					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 1535);
						chasis->stablishValueLeaf("motor1", 0, 512);
						chasis->stablishValueLeaf("motor2", 0, 1535);
						//printHierarchy();
					}
					break;
				case MOVEMENT_LEFT:
					
					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 1022);
						chasis->stablishValueLeaf("motor1", 0, 2046);
						chasis->stablishValueLeaf("motor2", 0, 0);
						//printHierarchy();
					}
					break;
				case MOVEMENT_RIGHT:
					
					chasis = searchComponent("Chasis");
					if(chasis != NULL){
						chasis->stablishValueLeaf("motor0", 0, 1022);
						chasis->stablishValueLeaf("motor1", 0, 0);
						chasis->stablishValueLeaf("motor2", 0, 1022);
						//printHierarchy();
					}
					break;
			}
			break;
		case HUMANOID:
			Component *right_arm;
			Component *left_arm;
			switch (action->getAction())
			{
				case CENTER_SELF:
					
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 512, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 512, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					//printHierarchy();
					break;
				case MOVEMENT_UP:
					
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 650, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 370, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					//printHierarchy();
					break;
				case MOVEMENT_DOWN:
					
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 370, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 650, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					//printHierarchy();
					break;
				case MOVEMENT_LEFT:
					
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 512, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 650, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					//printHierarchy();
					break;
				case MOVEMENT_RIGHT:
					
					right_arm = searchComponent("Right Arm");
					left_arm = searchComponent("Left Arm");
					if(right_arm != NULL && left_arm != NULL){
						right_arm->stablishValueLeaf("motor3", 370, 0);	
						right_arm->stablishValueLeaf("motor5", 512, 0);
						left_arm->stablishValueLeaf("motor4", 512, 0);
						left_arm->stablishValueLeaf("motor6", 512, 0);
					}
					//printHierarchy();
					break;
			}
			break;
	}
}
Пример #26
0
void ERModel::movedComponentPosition( int targetNodeID, int moveDistance_x, int moveDistance_y )
{
	Component* movedComponent = searchComponent(targetNodeID);
	movedComponent->setSx(movedComponent->getSx() + moveDistance_x);
	movedComponent->setSy(movedComponent->getSy() + moveDistance_y);
}