Пример #1
0
void VisualDebugger::createIdByLineCorrelation(UML::Element *elem, int& line)
{
	UML::Element *curElem = dynamic_cast<UML::NodeElement *>(elem);
	if (curElem && elem->id().element().compare("InitialNode") != 0) {
		if (elem->id().element().compare("Action") == 0) {
			mIdByLineCorrelation[line] = elem->id();
			line++;
			if (mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).count() != 0) {
				Id nextEdge = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).at(0);
				createIdByLineCorrelation(mEditor->mvIface()->scene()->getElem(nextEdge), line);
			} else {
				error(missingEndNode);
				mHasNotEndWithFinalNode = true;
			}
		} else {
			if (elem->id().element().compare("ConditionNode") == 0) {
				mIdByLineCorrelation[line] = elem->id();
				line++;
				IdList outLinks = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id());
				Id falseEdge = falseEdge.rootId();
				Id trueEdge = trueEdge.rootId();
				for (int i=0; i<outLinks.count(); i++) {
					bool type = getProperty(outLinks.at(i), "type").toBool();
					if (type) {
						trueEdge = outLinks.at(i);
					} else {
						falseEdge = outLinks.at(i);
					}
				}
				createIdByLineCorrelation(mEditor->mvIface()->scene()->getElem(trueEdge), line);
				line++;
				if (falseEdge != falseEdge.rootId()) {
					line++;
					createIdByLineCorrelation(mEditor->mvIface()->scene()->getElem(falseEdge), line);
					line++;
				}
			} else {
				mIdByLineCorrelation[line] = elem->id();
			}
		}
	} else {
		if (elem->id().element().compare("InitialNode") != 0) {
			Id nextNode  = mLogicalModelApi.logicalRepoApi().to(elem->id());
			createIdByLineCorrelation(mEditor->mvIface()->scene()->getElem(nextNode), line);
		} else {
			Id nextEdge = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).at(0);
			createIdByLineCorrelation(mEditor->mvIface()->scene()->getElem(nextEdge), line);
		}
	}
}
Пример #2
0
void VisualDebugger::generateCode(UML::Element *elem, QFile &codeFile)
{
	UML::Element *curElem = dynamic_cast<UML::NodeElement *>(elem);
	if (curElem && elem->id().element().compare("InitialNode") != 0) {
		if (elem->id().element().compare("Action") == 0) {
			QString code = getProperty(curElem->id(), "process").toString();
			if (code.mid(0,4).compare("var ") == 0) {
				codeFile.write(code.mid(4).toAscii());
			} else {
				codeFile.write(code.toAscii());
			}

			codeFile.write("\n");
			if (mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).count() != 0) {
				Id nextEdge = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).at(0);
				generateCode(mEditor->mvIface()->scene()->getElem(nextEdge), codeFile);
			} else {
				error(VisualDebugger::missingEndNode);
				error(codeGenerationError);
				return;
			}
		} else {
			if (elem->id().element().compare("ConditionNode") == 0) {
				codeFile.write("if (");
				codeFile.write(getProperty(curElem->id(), "condition").toByteArray());
				codeFile.write(") {\n");
				IdList outLinks = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id());
				Id falseEdge = falseEdge.rootId();
				Id trueEdge = trueEdge.rootId();
				for (int i=0; i<outLinks.count(); i++) {
					bool type = getProperty(outLinks.at(i), "type").toBool();
					if (type) {
						trueEdge = outLinks.at(i);
					} else {
						falseEdge = outLinks.at(i);
					}
				}
				if (trueEdge == trueEdge.rootId()) {
					error(VisualDebugger::missingValidLink);
					error(codeGenerationError);
					return;
				}
				generateCode(mEditor->mvIface()->scene()->getElem(trueEdge), codeFile);
				codeFile.write("}\n");
				if (falseEdge != falseEdge.rootId()) {
					codeFile.write("else {\n");
					generateCode(mEditor->mvIface()->scene()->getElem(falseEdge), codeFile);
					codeFile.write("}\n");
				}
			}
		}
	} else {
		if (elem->id().element().compare("InitialNode") != 0) {
			Id nextNode = mLogicalModelApi.logicalRepoApi().to(elem->id());
			generateCode(mEditor->mvIface()->scene()->getElem(nextNode), codeFile);
		} else {
			Id nextEdge = mLogicalModelApi.logicalRepoApi().outgoingLinks(curElem->id()).at(0);
			generateCode(mEditor->mvIface()->scene()->getElem(nextEdge), codeFile);
		}
	}

	return;
}