Commit 11f575c7 authored by Ludovic Apvrille's avatar Ludovic Apvrille

Update on splitting ADs

parent 474efcdc
......@@ -78,11 +78,14 @@ RELEASE_STD_FILES_LICENSES = LICENSE LICENSE_CECILL_ENG LICENSE_CECILL_FR
all:
all: basic jar
svn:
date
svn update build.txt src/ui/DefaultText.java
$(JAVA) -jar $(BUILDER) $(BUILD_INFO) $(BUILD_TO_MODIFY)
svn commit build.txt src/ui/DefaultText.java -m 'update on build version: builder.txt'
svn --username apvrille commit build.txt src/ui/DefaultText.java -m 'update on build version: builder.txt'
$(JAVAC) $(CLASSPATH) $(TTOOL_SRC) $(TTOOL_SRC)/*.java
basicsvnapvrille:
......
......@@ -312,28 +312,28 @@ public class TMLCP extends TMLElement {
}
public void generateNexts() {
mainCP.generateNexts();
for(TMLCPActivityDiagram diag: otherCPs) {
diag.generateNexts();
}
mainCP.generateNexts();
for(TMLCPActivityDiagram diag: otherCPs) {
diag.generateNexts();
}
}
public void removeADConnectors() {
mainCP.removeADConnectors();
for(TMLCPActivityDiagram diag: otherCPs) {
diag.removeADConnectors();
}
mainCP.removeADConnectors();
for(TMLCPActivityDiagram diag: otherCPs) {
diag.removeADConnectors();
}
}
public void splitADs() {
ArrayList<TMLCPActivityDiagram> all = new ArrayList<TMLCPActivityDiagram>();
all.addAll(mainCP.splitADs());
for(TMLCPActivityDiagram diag: otherCPs) {
all.addAll(diag.splitADs());
}
otherCPs.addAll(all);
ArrayList<TMLCPActivityDiagram> all = new ArrayList<TMLCPActivityDiagram>();
all.addAll(mainCP.splitADs());
for(TMLCPActivityDiagram diag: otherCPs) {
all.addAll(diag.splitADs());
}
otherCPs.addAll(all);
}
public void printDataStructure() {
......@@ -361,9 +361,9 @@ public class TMLCP extends TMLElement {
//Print attributes
System.out.printf( "\tAttributes:\n");
for( j = 0; j < listAttributes.size(); j++ ) {
attr = listAttributes.get( j );
System.out.printf( "\t\t%s\t%s\t%s\n", attr.getName(), attr.getType(), attr.getInitialValue() );
}*/
attr = listAttributes.get( j );
System.out.printf( "\t\t%s\t%s\t%s\n", attr.getName(), attr.getType(), attr.getInitialValue() );
}*/
//Print list of AD sections
ArrayList<String> ADList;
......@@ -449,14 +449,14 @@ public class TMLCP extends TMLElement {
public String toString() {
String s = "\n*** Communication Pattern: " + getName() + "***\n";
s += mainCP.toString();
s += mainCP.toString();
for( tmltranslator.tmlcp.TMLCPActivityDiagram diag: otherCPs) {
s += diag.toString();
}
for( tmltranslator.tmlcp.TMLCPActivityDiagram diag: otherCPs) {
s += diag.toString();
}
for( tmltranslator.tmlcp.TMLCPSequenceDiagram diag: sds ) {
s += sds.toString();
s += sds.toString();
}
return s;
}
......
This diff is collapsed.
......@@ -108,12 +108,12 @@ public class TMLCPActivityDiagram extends TMLElement {
public int getSize() { return elements.size();}
public TMLCPElement getElementByReference(Object referenceObject) {
for(TMLCPElement elt: elements) {
if (elt.getReferenceObject() == referenceObject) {
return elt;
}
}
return null;
for(TMLCPElement elt: elements) {
if (elt.getReferenceObject() == referenceObject) {
return elt;
}
}
return null;
}
/*public boolean checkVariableNoType( TMLAttribute _attr ) {
......@@ -184,7 +184,7 @@ public class TMLCPActivityDiagram extends TMLElement {
}
public boolean contains(TMLCPElement elt) {
return elements.contains(elt);
return elements.contains(elt);
}
public TMLCPElement getElementByName(String name) {
......@@ -213,7 +213,7 @@ public class TMLCPActivityDiagram extends TMLElement {
}
public TMLCPElement getStartElement() {
return start;
return start;
}
public void addTMLCPElement(TMLCPElement _elt) {
......@@ -311,97 +311,116 @@ public class TMLCPActivityDiagram extends TMLElement {
int id = 0;
TMLCPActivityDiagram diag;
TraceManager.addDev("Splitting AD: " + getName());
TraceManager.addDev("Splitting AD: " + getName());
// For each junction, we create a new AD
ArrayList<TMLCPJunction> junctions = new ArrayList<TMLCPJunction>();
ArrayList<TMLCPRefAD> refsAD = new ArrayList<TMLCPRefAD>();
ArrayList<TMLCPElement> toBeRemoved = new ArrayList<TMLCPElement>();
ArrayList<TMLCPRefAD> refsAD = new ArrayList<TMLCPRefAD>();
ArrayList<TMLCPElement> toBeRemoved = new ArrayList<TMLCPElement>();
HashMap<TMLCPJunction, TMLCPActivityDiagram> refs = new HashMap<TMLCPJunction, TMLCPActivityDiagram>();
for(TMLCPElement elt: elements) {
if (elt instanceof TMLCPJunction) {
junctions.add((TMLCPJunction)elt);
diag = new TMLCPActivityDiagram(elt.getName() + "_" + id, referenceObject);
TMLCPStart start = new TMLCPStart("StartFrom_" + elt.getName(), elt.getReferenceObject());
diag.setStartElement(start);
diag.addTMLCPElement(start);
TMLCPStart start = new TMLCPStart("StartFrom_" + elt.getName(), elt.getReferenceObject());
diag.setStartElement(start);
diag.addTMLCPElement(start);
refs.put((TMLCPJunction)elt, diag);
TraceManager.addDev("Adding a new diag named: " + diag.getName());
TraceManager.addDev("Adding a new diag named: " + diag.getName());
}
}
// We replace all junctions by a call to the corresponding ref AD, keeping the same nexts
for(TMLCPJunction junction: junctions) {
TMLCPActivityDiagram toAD = refs.get(junction);
TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), junction.getReferenceObject());
refsAD.add(ref);
elements.remove(junction);
elements.add(ref);
for(TMLCPElement elt: elements) {
elt.replaceNext(junction, ref);
}
ref.setNexts(junction.getNextElements());
}
// We replace all elements leading to a junction by a call to the corresponding ref AD, keeping the same nexts
for(TMLCPJunction junction: junctions) {
TMLCPActivityDiagram toAD = refs.get(junction);
//TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), junction.getReferenceObject());
//refsAD.add(ref);
elements.remove(junction);
//elements.add(ref);
// Replacing next to junction by new refs
int index;
int ID = 0;
for(TMLCPElement elt: elements) {
while(((index = elt.getNextElements().indexOf(junction)) != -1)) {
TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName() + "_" + ID, junction.getReferenceObject());
ID ++;
refsAD.add(ref);
//elements.add(ref);
elt.setNextElementAtIndex(ref, index);
/*TMLCPStop stop = new TMLCPStop(ref.getName() + "__stop_after_ref_" + ID, ref.getReferenceObject());
elements.add(stop);
ref.addNextElement(stop);*/
}
//ref.setNexts(junction.getNextElements());
}
}
// Removing nexts in new refs, and putting a stop
for(TMLCPRefAD ref: refsAD) {
ref.clearNexts();
elements.add(ref);
TMLCPStop stop = new TMLCPStop(ref.getName() + "__stop_after_ref", ref.getReferenceObject());
elements.add(stop);
ref.addNextElement(stop);
}
// Moving elements from old AD to split ADs
int cpt = 0;
int cpt = 0;
for(TMLCPJunction junction: junctions) {
diag = refs.get(junction);
TMLCPRefAD refAD = refsAD.get(cpt);
cpt++;
// To be modified-> add elements from RefADs
// Also, avoid to add already met elements
diag = refs.get(junction);
//TMLCPRefAD refAD = refsAD.get(cpt);
//cpt++;
// To be modified-> add elements from RefADs
// Also, avoid to add already met elements
addElementsFromJunction(junction, diag.getStartElement(), diag, refs, toBeRemoved);
}
// Removing elements from main diagram
for(TMLCPElement elt: toBeRemoved) {
elements.remove(elt);
}
// Removing elements from main diagram
for(TMLCPElement elt: toBeRemoved) {
elements.remove(elt);
}
// Removing nexts in new refs
for(TMLCPRefAD ref: refsAD) {
ref.clearNexts();
}
// Returns new elements
return refs.values();
}
private void addElementsFromJunction(TMLCPElement originInOld, TMLCPElement originInNew, TMLCPActivityDiagram newDiag, HashMap<TMLCPJunction, TMLCPActivityDiagram> refs, ArrayList<TMLCPElement> toBeRemoved) {
if (originInOld.getNextElements() == null) {
return;
}
for(TMLCPElement elt: originInOld.getNextElements()) {
TraceManager.addDev("Exploring elt (0):" + elt.getName());
if (elt instanceof TMLCPJunction) {
// Must replace the junction by a ref to an AD
TMLCPActivityDiagram toAD = refs.get((TMLCPJunction)elt);
TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), elt.getReferenceObject());
newDiag.addTMLCPElement(ref);
originInNew.setNextElement(ref);
} else {
TraceManager.addDev("Exploring elt (1):" + elt.getName());
if (originInOld != originInNew) {
originInNew.addNextElement(elt);
}
if (!newDiag.contains(elt)) {
newDiag.addTMLCPElement(elt);
toBeRemoved.add(elt);
addElementsFromJunction(elt, elt, newDiag, refs, toBeRemoved);
}
}
}
if (originInOld.getNextElements() == null) {
return;
}
for(TMLCPElement elt: originInOld.getNextElements()) {
TraceManager.addDev("Exploring elt (0):" + elt.getName());
if (elt instanceof TMLCPJunction) {
// Must replace the junction by a ref to an AD
TMLCPActivityDiagram toAD = refs.get((TMLCPJunction)elt);
TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), elt.getReferenceObject());
newDiag.addTMLCPElement(ref);
originInNew.setNextElement(ref);
} else {
TraceManager.addDev("Exploring elt (1):" + elt.getName());
if (originInOld != originInNew) {
originInNew.addNextElement(elt);
}
if (!newDiag.contains(elt)) {
newDiag.addTMLCPElement(elt);
toBeRemoved.add(elt);
addElementsFromJunction(elt, elt, newDiag, refs, toBeRemoved);
}
}
}
}
public String toString() {
String s = "*** Activity diagram " + getName() + "\n";
for(TMLCPElement elt: elements) {
s += elt.toString();
}
return s + "\n";
String s = "*** Activity diagram " + getName() + "\n";
for(TMLCPElement elt: elements) {
s += elt.toString();
}
return s + "\n";
}
} //End of class
......@@ -78,6 +78,10 @@ public abstract class TMLCPElement extends TMLElement {
nexts.clear();
addNextElement(_elt);
}
public void setNextElementAtIndex(TMLCPElement _elt, int _index) {
nexts.set(_index, _elt);
}
public void clearNexts() {
nexts.clear();
......@@ -99,6 +103,10 @@ public abstract class TMLCPElement extends TMLElement {
}
public String toShortString() {
return getClass().getCanonicalName() + " " + getName() + "\n";
}
......
......@@ -1928,23 +1928,23 @@ public class GTMLModeling {
TGComponent tgc;
if( syntax.hasErrors() > 0 ) {
for( TMLCPError error: syntax.getErrors() ) {
if( error.type == TMLCPError.ERROR_STRUCTURE ) {
type = CheckingError.STRUCTURE_ERROR;
}
else {
type = CheckingError.BEHAVIOR_ERROR;
}
ce = new CheckingError( type, error.message );
tgc = listE.getTG( error.element );
if ( tgc != null ) {
ce.setTDiagramPanel( tgc.getTDiagramPanel() );
ce.setTGComponent( tgc );
}
ce.setTMLTask( error.task );
checkingErrors.add( ce );
}
}
for( TMLCPError error: syntax.getErrors() ) {
if( error.type == TMLCPError.ERROR_STRUCTURE ) {
type = CheckingError.STRUCTURE_ERROR;
}
else {
type = CheckingError.BEHAVIOR_ERROR;
}
ce = new CheckingError( type, error.message );
tgc = listE.getTG( error.element );
if ( tgc != null ) {
ce.setTDiagramPanel( tgc.getTDiagramPanel() );
ce.setTGComponent( tgc );
}
ce.setTMLTask( error.task );
checkingErrors.add( ce );
}
}
/*makeCPDataStructure();
if (!makeTMLModeling()) {
......@@ -2201,13 +2201,14 @@ public class GTMLModeling {
//TraceManager.addDev( "PANEL number: " + panelCounter + " " + panelList.get( panelCounter ) );
}
TraceManager.addDev( "Before correcting references. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
TraceManager.addDev( "Before correcting references. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
tmlcp.correctReferences(); //Update references to the right activity and sequence diagrams
TraceManager.addDev( "After correcting references and before splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
TraceManager.addDev( "After correcting references and before splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
//tmlcp.generateNexts(); // Add nexts elements to CPElements
//tmlcp.removeADConnectors(); // Remove connectors since nexts have been filled
tmlcp.splitADs(); // Splitting ADs so as to remove junctions -> new ADs are introduced for each junction inside an AD
TraceManager.addDev( "After splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
TraceManager.addDev( "After splitting ADs. OriginalCP:" + tmlcp.toString() );
TraceManager.addDev( "After splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() );
for( TMLCPSequenceDiagram seqDiag: tmlcp.getCPSequenceDiagrams() ) {
TraceManager.addDev( "**********" );
......@@ -2390,8 +2391,8 @@ public class GTMLModeling {
LinkedList elemList = panel.getComponentList();
//TraceManager.addDev("Adding to the data structure the elements of: " + panel.getName() );
//order messages according to the inverse of Y coordinate
int j;
TGComponent elem;
int j;
TGComponent elem;
for(j = 0; j < elemList.size(); j++ ) {
elem = (TGComponent) elemList.get(j);
//include the package name of the class to avoid confusion with the graphical TMLSDInstance
......@@ -2470,11 +2471,11 @@ public class GTMLModeling {
}
SD.addInstance( instance );
}
} //End of for over internal elements
for(j = 0; j < elemList.size(); j++ ) {
elem = (TGComponent) elemList.get(j);
if( elem instanceof TGConnectorMessageTMLSD ) {
for(j = 0; j < elemList.size(); j++ ) {
elem = (TGComponent) elemList.get(j);
if( elem instanceof TGConnectorMessageTMLSD ) {
TraceManager.addDev("Analyzing message:" + elem);
connector = (TGConnectorMessageTMLSD) elemList.get(j);
String sender = connector.getTGConnectingPointP1().getFather().getName();
......@@ -2494,8 +2495,8 @@ public class GTMLModeling {
}
}
}
}
}
return SD;
}//End else name does not exist yet
} //End of method createSequenceDiagramDataStructure
......
......@@ -114,9 +114,16 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
private Vector<Point> points;
private Vector<AvatarSimulationTransaction> transactionsOfPoints;
// Saving states
private class StateYCd {
public String stateName;
public int y;
}
private HashMap<AvatarSimulationBlock, ArrayList<StateYCd>> statesMap = new HashMap<AvatarSimulationBlock, ArrayList<StateYCd>>();
// Graphics
private Graphics2D lastGraphics;
private boolean trace = true;
......@@ -166,6 +173,8 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
return;
}
statesMap.clear();
//TraceManager.addDev("Painting components");
lastGraphics = (Graphics2D)g;
super.paintComponent(g);
......@@ -290,6 +299,17 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
if (ast.executedElement instanceof AvatarState) {
if ((showHiddenStates) || (!((AvatarState)ast.executedElement).isHidden())) {
newCurrentY = drawState(g, ast, (AvatarState)(ast.executedElement), xOfBlock, currentY);
ArrayList<StateYCd> states = null;
if (statesMap.containsKey(ast.asb)) {
states = statesMap.get(ast.asb);
} else {
states = new ArrayList<StateYCd>();
statesMap.put(ast.asb, states);
}
StateYCd ycd = new StateYCd();
ycd.stateName = ((AvatarState)(ast.executedElement)).getName();
ycd.y = currentY + verticalLink;
states.add(ycd);
}
} else if (ast.executedElement instanceof AvatarTransition) {
newCurrentY = drawTransition(g, (AvatarTransition)(ast.executedElement), ast, xOfBlock, currentY);
......@@ -700,6 +720,27 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
drawInfo = false;
}
private String getNameOfState(AvatarSimulationBlock block, int y) {
if (!(statesMap.containsKey(block))) {
return null;
}
String name = null;
ArrayList<StateYCd> ycd = statesMap.get(block);
if (ycd == null) {
return name;
}
for(StateYCd st: ycd) {
if (st.y > y) {
return name;
}
name = st.stateName;
}
return name;
}
private void drawInfo(Graphics g) {
String timeValue = "@" + clockValueMouse;
Color c = g.getColor();
......@@ -709,7 +750,7 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
g.drawString(timeValue, maxX-spaceAtEnd + 1, yMouse+g.getFontMetrics().getHeight()/2);
TraceManager.addDev("yMouse=" + yMouse);
//TraceManager.addDev("yMouse=" + yMouse);
/*if (minIdValueMouse == maxIdValueMouse) {
g.drawString("ID: " + minIdValueMouse, 10, yMouse+(g.getFontMetrics().getHeight()/2)+12);
......@@ -722,6 +763,9 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
Vector<AvatarSimulationBlock> blocks = ass.getSelectedSimulationBlocks();
int x = spaceAtEnd;
Font normal = g.getFont();
Font it = normal.deriveFont(Font.ITALIC);
for(AvatarSimulationBlock block: blocks) {
name = block.getBlock().getName();
w = g.getFontMetrics().stringWidth(name);
......@@ -729,7 +773,18 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous
// Write the name of the current state
name = getNameOfState(block, yMouse);
if (name == null) {
name = "start state";
} else {
name = "state: " + name;
}
g.setFont(it);
w = g.getFontMetrics().stringWidth(name);
g.drawString(name, x + ((spaceBetweenLifeLines-w)/2), yMouse + (6 * spaceVerticalText));
g.setFont(normal);
// Add the space between lifelines
x += spaceBetweenLifeLines;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment