[Mobies-commit] [commit] r3571 - GReAT/trunk/Tools/UMTInterpreters/Blockify
ksmyth at redhat1.isis.vanderbilt.edu
ksmyth at redhat1.isis.vanderbilt.edu
Mon Nov 29 12:41:59 CST 2010
Author: ksmyth
Date: Mon Nov 29 12:41:58 2010
New Revision: 3571
Log:
Fixes for Refs and RefPorts
Modified:
GReAT/trunk/Tools/UMTInterpreters/Blockify/CompareFunction.h
GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.cpp
GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.h
Modified: GReAT/trunk/Tools/UMTInterpreters/Blockify/CompareFunction.h
==============================================================================
--- GReAT/trunk/Tools/UMTInterpreters/Blockify/CompareFunction.h Mon Nov 29 12:01:45 2010 (r3570)
+++ GReAT/trunk/Tools/UMTInterpreters/Blockify/CompareFunction.h Mon Nov 29 12:41:58 2010 (r3571)
@@ -1,33 +1,32 @@
#include <string>
#include <stdlib.h>
+int getTransformXPos(std::string lhs_pos) {
+ std::string::size_type findTrans = lhs_pos.find("Transform");
+ if (findTrans != std::string::npos) {
+ lhs_pos = lhs_pos.substr(findTrans);
+ // std::cout << "Now lhs_pos = " << lhs_pos << std::endl;
+ }
+ findTrans = lhs_pos.find("(");
+ lhs_pos = lhs_pos.substr(findTrans + 1);
+ findTrans = lhs_pos.find(")");
+ lhs_pos = lhs_pos.substr(0, findTrans);
+ std::cout << "After trim lhs_pos = " << lhs_pos << std::endl;
+ findTrans = lhs_pos.find(',');
+ return atoi(lhs_pos.substr(0, findTrans).c_str());
+}
template <class T>
bool XPosCmp( const T& lhs, const T& rhs) {
std::string lhs_pos= lhs.position();
-std::string rhs_pos= rhs.position();
+ std::string rhs_pos= rhs.position();
-std::string::size_type findTrans = lhs_pos.find("Transform");
-lhs_pos = lhs_pos.substr(findTrans);
-std::cout << "Now lhs_pos = " << lhs_pos << std::endl;
-findTrans = lhs_pos.find("(");
-lhs_pos = lhs_pos.substr(findTrans+1);
-lhs_pos = lhs_pos.substr(0,lhs_pos.size()-2);
-std::cout << "After trim lhs_pos = " << lhs_pos << std::endl;
-findTrans = lhs_pos.find(',');
-int lhs_x = atoi(lhs_pos.substr(0,findTrans).c_str());
-
-findTrans = rhs_pos.find("Transform");
-rhs_pos = rhs_pos.substr(findTrans);
-findTrans = rhs_pos.find("(");
-rhs_pos = rhs_pos.substr(findTrans+1);
-rhs_pos = rhs_pos.substr(0, rhs_pos.size()-2);
-findTrans = rhs_pos.find(',');
-int rhs_x = atoi(rhs_pos.substr(0,findTrans).c_str());
+ int lhs_x = getTransformXPos(lhs_pos);
+ int rhs_x = getTransformXPos(rhs_pos);
-std::cout << "LHSX = " << lhs_x << " and RHSX = " << rhs_x << std::endl;
+ // std::cout << "LHSX = " << lhs_x << " and RHSX = " << rhs_x << std::endl;
-return (lhs_x<rhs_x);
+ return (lhs_x<rhs_x);
}
template <class BASE, class T>
Modified: GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.cpp
==============================================================================
--- GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.cpp Mon Nov 29 12:01:45 2010 (r3570)
+++ GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.cpp Mon Nov 29 12:41:58 2010 (r3571)
@@ -21,8 +21,8 @@
typedef map<UMLModelTransformer::In, UMLModelTransformer::In> IIMap;
typedef map<UMLModelTransformer::Out, UMLModelTransformer::Out> OOMap;
-void CreateInputPorts(UMLModelTransformer::Expression &blank, UMLModelTransformer::Expression old, UMLModelTransformer::Expression focusObj, IIMap &iMap);
-void CreateOutputPorts(UMLModelTransformer::Expression &blank, UMLModelTransformer::Expression old, UMLModelTransformer::Expression focusObj, OOMap &oMap);
+void CreateInputPorts(UMLModelTransformer::Expression &blank, Udm::Object& oold, UMLModelTransformer::Expression focusObj, IIMap &iMap);
+void CreateOutputPorts(UMLModelTransformer::Expression &blank, Udm::Object& oold, UMLModelTransformer::Expression focusObj, OOMap &oMap);
void FillMap(IOMap &portMap, list<Udm::Object> objs);
template<typename T> void CreateConnections(T inMap, UMLModelTransformer::Block &nBlock);
@@ -38,6 +38,13 @@
return 0;
}
+UMLModelTransformer::Expression GetExpression(const Udm::Object& exprOrRef) {
+ if (exprOrRef.type() == UMLModelTransformer::ExpressionRef::meta) {
+ return UMLModelTransformer::ExpressionRef::Cast(exprOrRef).ref();
+ } else {
+ return UMLModelTransformer::Expression::Cast(exprOrRef);
+ }
+}
/*
@@ -109,7 +116,7 @@
/* Use a list of objects so that it's easier to sort */
list<Udm::Object> selObjs(selectedObjects.begin(), selectedObjects.end()); //selObjs now has the sorted objects
- selObjs.sort(ptr_fun(XPosCmp_caster<Udm::Object, UMLModelTransformer::Expression>));
+ selObjs.sort(ptr_fun(XPosCmp_caster<Udm::Object, UMLModelTransformer::MgaObject>));
/* These maps keep track of the ports that we need to connect; the GME backend doesn't allow invalid connections, so
we must first discover the connections, keep track of them in the maps, move the objects, and then use the maps to
@@ -123,17 +130,18 @@
UMLModelTransformer::Expression focusExpr = UMLModelTransformer::Expression::Cast(focusObject);
UMLModelTransformer::Block nBlock = UMLModelTransformer::Block::Create(focusExpr); /* The new block into which we insert the selected objs */
- nBlock.position() = (UMLModelTransformer::Expression::Cast(selObjs.front())).position();
+ // FIXME: this doesn't work if selObjs.front() is a ExpressionRef: it sets the position in the Template aspect only
+ nBlock.position() = (UMLModelTransformer::MgaObject::Cast(selObjs.front())).position();
nBlock.name() = "NewBlock";
- CreateInputPorts(nBlock, UMLModelTransformer::Expression::Cast(selObjs.front()), focusExpr, inputMap);
- CreateOutputPorts(nBlock, UMLModelTransformer::Expression::Cast(*(--selObjs.end())), focusExpr, outputMap);
+ CreateInputPorts(nBlock, selObjs.front(), focusExpr, inputMap);
+ CreateOutputPorts(nBlock, *(--selObjs.end()), focusExpr, outputMap);
/* Move all of the selected objects to the newly created block; we can do this now because we have already put the ports that need to
be connected into a map */
for(list<Udm::Object>::iterator lit = selObjs.begin();lit!=selObjs.end();++lit)
{
- UMLModelTransformer::Expression expression = UMLModelTransformer::Expression::Cast(*lit);
+ UMLModelTransformer::MgaObject expression = UMLModelTransformer::MgaObject::Cast(*lit);
expression.parent() = nBlock;
}
@@ -158,18 +166,25 @@
}
}
-void CreateInputPorts(UMLModelTransformer::Expression &blank, UMLModelTransformer::Expression old, UMLModelTransformer::Expression focusObj, IIMap &inputMap)
+void CreateInputPorts(UMLModelTransformer::Expression &blank, Udm::Object& oold, UMLModelTransformer::Expression focusObj, IIMap &inputMap)
{
+ UMLModelTransformer::Expression old = GetExpression(oold);
+
set<UMLModelTransformer::In> inPorts = old.In_kind_children();
for(set<UMLModelTransformer::In>::iterator it = inPorts.begin(); it != inPorts.end(); ++it)
{
set< UMLModelTransformer::Sequence> sequences= (*it).srcSequence();
- if(!(sequences.empty())) //the input port had some incoming connections, so find them and re-assemble :)
+ //the input port had some incoming connections, so find them and re-assemble :)
{
for(set< UMLModelTransformer::Sequence>::iterator seqIt = sequences.begin(); seqIt != sequences.end(); ++seqIt)
{
+ UMLModelTransformer::ExpressionRef rpCont = seqIt->In_end__rp_helper();
+ if ((rpCont && rpCont != oold) ||
+ (!rpCont && old != oold)) {
+ continue;
+ }
UMLModelTransformer::Port otherOut= (*seqIt).srcSequence_end();
if(Uml::IsDerivedFrom( otherOut.type(), UMLModelTransformer::Out::meta))
{
@@ -188,6 +203,10 @@
UMLModelTransformer::Sequence nSeq = UMLModelTransformer::Sequence::Create(focusObj);
nSeq.srcSequence_end() = currOut;
nSeq.dstSequence_end() = nIn;
+ nSeq.Out_end__rp_helper() = seqIt->Out_end__rp_helper();
+ if (oold.type() == UMLModelTransformer::ExpressionRef::meta) {
+ nSeq.In_end__rp_helper() = UMLModelTransformer::ExpressionRef::Cast(oold);
+ }
inputMap.insert(pair<UMLModelTransformer::In, UMLModelTransformer::In>(nIn, (*it)));
}
else if(Uml::IsDerivedFrom( otherOut.type(), UMLModelTransformer::In::meta)) /* Input to Input */
@@ -207,6 +226,10 @@
UMLModelTransformer::Sequence nSeq = UMLModelTransformer::Sequence::Create(focusObj);
nSeq.srcSequence_end() = currOut;
nSeq.dstSequence_end() = nIn;
+ nSeq.Out_end__rp_helper() = seqIt->Out_end__rp_helper();
+ if (oold.type() == UMLModelTransformer::ExpressionRef::meta) {
+ nSeq.In_end__rp_helper() = UMLModelTransformer::ExpressionRef::Cast(oold);
+ }
inputMap.insert(pair<UMLModelTransformer::In, UMLModelTransformer::In>(nIn, (*it)));
}
@@ -215,18 +238,24 @@
}
}
-void CreateOutputPorts(UMLModelTransformer::Expression &blank, UMLModelTransformer::Expression old, UMLModelTransformer::Expression focusObj, OOMap &outputMap)
+void CreateOutputPorts(UMLModelTransformer::Expression &blank, Udm::Object& oold, UMLModelTransformer::Expression focusObj, OOMap &outputMap)
{
+ UMLModelTransformer::Expression old = GetExpression(oold);
set<UMLModelTransformer::Out> outPorts = old.Out_kind_children();
for(set<UMLModelTransformer::Out>::iterator it = outPorts.begin(); it != outPorts.end(); ++it)
{
set< UMLModelTransformer::Sequence> sequences= (*it).dstSequence();
- if(!(sequences.empty())) //the input port had some incoming connections, so find them and re-assemble :)
+ //the input port had some incoming connections, so find them and re-assemble :)
{
for(set< UMLModelTransformer::Sequence>::iterator seqIt = sequences.begin(); seqIt != sequences.end(); ++seqIt)
{
+ UMLModelTransformer::ExpressionRef rpCont = seqIt->Out_end__rp_helper();
+ if ((rpCont && rpCont != oold) ||
+ (!rpCont && old != oold)) {
+ continue;
+ }
UMLModelTransformer::Port otherIn= (*seqIt).dstSequence_end();
if(Uml::IsDerivedFrom( otherIn.type(), UMLModelTransformer::In::meta))
{
@@ -245,6 +274,10 @@
nOut.name() = (*it).name();
nSeq.srcSequence_end() = nOut;
nSeq.dstSequence_end() = currIn;
+ nSeq.In_end__rp_helper() = seqIt->In_end__rp_helper();
+ if (oold.type() == UMLModelTransformer::ExpressionRef::meta) {
+ nSeq.Out_end__rp_helper() = UMLModelTransformer::ExpressionRef::Cast(oold);
+ }
outputMap.insert(pair<UMLModelTransformer::Out, UMLModelTransformer::Out>(*it, nOut));
}
@@ -265,6 +298,10 @@
nOut.name() = (*it).name();
nSeq.srcSequence_end() = nOut;
nSeq.dstSequence_end() = currIn;
+ nSeq.In_end__rp_helper() = seqIt->In_end__rp_helper();
+ if (oold.type() == UMLModelTransformer::ExpressionRef::meta) {
+ nSeq.Out_end__rp_helper() = UMLModelTransformer::ExpressionRef::Cast(oold);
+ }
outputMap.insert(pair<UMLModelTransformer::Out, UMLModelTransformer::Out>(*it, nOut));
}
@@ -281,8 +318,7 @@
{
if(it == objs.begin())
continue;
-
- UMLModelTransformer::Expression expr = UMLModelTransformer::Expression::Cast(*it);
+ UMLModelTransformer::Expression expr = GetExpression(*it);
set<UMLModelTransformer::In> inPorts = expr.In_kind_children();
for(set<UMLModelTransformer::In>::iterator portItr = inPorts.begin(); portItr != inPorts.end(); ++portItr)
{
@@ -305,38 +341,3 @@
}
-
-#ifdef _DEBUG
-/*****************************************************/
-/* Debug time helper function. If the object has an */
-/* attribute called "name", this function retreives */
-/* it to help you to find it in the model during the */
-/* application development. Usualy every GME Object */
-/* has a "name" attribute. If an object hapens not */
-/* to have it,function retreives <no name specified>.*/
-/*****************************************************/
-string CUdmApp::ExtractName(Udm::Object ob)
-{
- Uml::Class cls= ob.type();
- set<Uml::Attribute> attrs=cls.attributes();
-
- // Adding parent attributes
- set<Uml::Attribute> aattrs=Uml::AncestorAttributes(cls);
- attrs.insert(aattrs.begin(),aattrs.end());
-
- for(set<Uml::Attribute>::iterator ai = attrs.begin();ai != attrs.end(); ai++)
- {
- if(string(ai->type())=="String")
- {
- string str=ai->name();
- if(str=="name")
- {
- string value=ob.getStringAttr(*ai);
- if(value.empty())value="<empty string>";
- return value;
- }
- }
- }
- return string("<no name specified>");
-}
-#endif
Modified: GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.h
==============================================================================
--- GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.h Mon Nov 29 12:01:45 2010 (r3570)
+++ GReAT/trunk/Tools/UMTInterpreters/Blockify/UdmApp.h Mon Nov 29 12:41:58 2010 (r3571)
@@ -28,12 +28,6 @@
public:
static int Initialize();
static void UdmMain(Udm::DataNetwork* p_backend,Udm::Object currentObject, set<Udm::Object> selectedObjects, long param);
-
-#ifdef _DEBUG
- static string ExtractName(Udm::Object ob);
-#endif
-
-
};
#endif // !defined(AFX_UDMAPP_H__296A93EB_6DB6_4179_AA0B_A3D799FB3A1C__INCLUDED_)
More information about the Mobies-commit
mailing list