Commit 68d8cff1 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Merge branch 'minh-issue-186' into 'master'

issue 186 : clone composite component

See merge request !120
parents ddaeaec3 dd05ae21
......@@ -3593,7 +3593,7 @@ public class GTURTLEModeling {
}
public String makeXMLFromSelectedComponentOfADiagram(TDiagramPanel tdp, int copyMaxId, int _decX, int _decY) {
public String makeXMLFromSelectedComponentOfADiagram(TDiagramPanel tdp, int copyMaxId, int _decX, int _decY, boolean cloneEvenIfNonNullFather) {
StringBuffer sb = new StringBuffer();
//TraceManager.addDev("Making copy");
......@@ -3608,7 +3608,7 @@ public class GTURTLEModeling {
StringBuffer s;
String str;
s = tdp.saveSelectedInXML();
s = tdp.saveSelectedInXML(cloneEvenIfNonNullFather);
final Vector<TCDTClass> classes = tdp.selectedTclasses();
......
......@@ -627,8 +627,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
mode = NORMAL;
}
public StringBuffer saveSelectedInXML() {
StringBuffer s = componentsInXML(true);
public StringBuffer saveSelectedInXML(boolean cloneEvenIfNonNullFather) {
StringBuffer s = componentsInXML(true, cloneEvenIfNonNullFather);
if (s == null) {
return null;
}
......@@ -638,7 +638,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
sb.append("\n");
sb.append(getXMLSelectedTail());
//TraceManager.addDev("xml of selected components:" + sb);
//TraceManager.addDev("XML of selected components:" + sb);
return sb;
}
......@@ -663,28 +663,37 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
sb.append(tgc.saveInXML());
sb.append("\n");
sb.append(getXMLCloneTail());
//TraceManager.addDev("sb=\n" + sb);
TraceManager.addDev("sb=\n" + sb);
return sb;
}
private StringBuffer componentsInXML(boolean selected) {
return componentsInXML(selected, false);
}
private StringBuffer componentsInXML(boolean selected, boolean cloneEvenIfNonNullFather) {
StringBuffer sb = new StringBuffer();
StringBuffer s;
//Added by Solange to see the components in the list
// LinkedList<TGComponent> ruteoList = this.componentList;
//
for (TGComponent tgc : this.componentList) {
for (TGComponent tgc : this.getAllComponent()){
//for (TGComponent tgc : this.componentList) {
if ((selected == false) || (tgc.isSelected())) {
s = tgc.saveInXML();
if (s == null) {
return null;
}
sb.append(s);
sb.append("\n");
if((tgc.getFather() == null) || (cloneEvenIfNonNullFather)) {
//TraceManager.addDev("Cloning:" + tgc);
s = tgc.saveInXML(true, cloneEvenIfNonNullFather);
//TraceManager.addDev("Saving component in xml:" + s);
if (s == null) {
return null;
}
sb.append(s);
sb.append("\n");
}
}
}
return sb;
}
......@@ -1051,6 +1060,24 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
return ll;
}
//issue 186
// get all list of all primitive components, composite components and connectors
public List<TGComponent> getAllComponent() {
List<TGComponent> ll = new LinkedList<TGComponent>();
ll.addAll(this.componentList);
for (TGComponent tgc : this.componentList) {
if (tgc instanceof TMLCCompositeComponent) {
for(TGComponent tg : ((TMLCCompositeComponent)tgc).getRecursiveAllInternalComponent()) {
if(tg instanceof TMLCCompositeComponent) {
ll.add(tg);
}
}
ll.addAll(((TMLCCompositeComponent)tgc).getAllPrimitiveComponents());
}
}
return ll;
}
// Adding connector
public void addingTGConnector() {
listPoint = new Vector<Point>();
......@@ -1361,23 +1388,26 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
return v;
}
//issue 186
public Vector<TMLCPrimitiveComponent> selectedCPrimitiveComponent() {
Vector<TMLCPrimitiveComponent> v = null;
for (TGComponent tgc : this.componentList)
for (TGComponent tgc : this.getAllComponent()){
if (tgc.isSelected()) {
if (tgc instanceof TMLCPrimitiveComponent) {
if (v == null)
v = new Vector<TMLCPrimitiveComponent>();
v.addElement((TMLCPrimitiveComponent) tgc);
}
}
if (tgc instanceof TMLCCompositeComponent) {
if (v == null)
v = new Vector<TMLCPrimitiveComponent>();
v.addAll(((TMLCCompositeComponent) (tgc)).getAllPrimitiveComponents());
}
if (tgc instanceof TMLCCompositeComponent) {
if (v == null)
v = new Vector<TMLCPrimitiveComponent>();
v.addAll(((TMLCCompositeComponent) (tgc)).getAllPrimitiveComponents());
}
}
return v;
}
......@@ -1707,7 +1737,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
}
if (e.getSource() == clone) {
cloneComponent(componentPopup.getTopFather());
//issue 186
cloneComponent(componentPopup, true);
repaint();
return;
}
......@@ -2191,7 +2222,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
}
public void makeCut() {
copyData = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel);
copyData = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel, false);
removeAllSelectedComponents();
mgui.changeMade(this, REMOVE_COMPONENT);
mode = NORMAL;
......@@ -2200,13 +2231,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
}
public void makeCopy() {
copyData = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel);
copyData = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel, false);
mgui.setMode(MainGUI.PASTE_OK);
return;
}
public void saveAsLibrary() {
String data = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel);
String data = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), xSel, ySel, false);
mgui.saveAsLibrary(data);
return;
}
......@@ -2371,11 +2402,16 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
}
}
public void cloneComponent(TGComponent _tgc) {
cloneComponent(_tgc, true);
}
/*
* #issue 82
* new cloneComponent added by Minh Hiep
*/
public void cloneComponent(TGComponent _tgc) {
public void cloneComponent(TGComponent _tgc, boolean cloneEvenIfNonNullFather) {
String clone;
Vector<TGComponent> connectorList = new Vector<>();
......@@ -2398,7 +2434,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
}
}
clone = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), _tgc.getX(), _tgc.getY());
clone = mgui.gtm.makeXMLFromSelectedComponentOfADiagram(this, getMaxIdSelected(), _tgc.getX(), _tgc.getY(), cloneEvenIfNonNullFather);
//TraceManager.addDev(clone);
_tgc.select(false);
for(int i = 0; i < connectorList.size(); i++){
......@@ -2414,7 +2451,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
JOptionPane.showMessageDialog(mgui.getFrame(), "Clone creation failed", "Exception", JOptionPane.INFORMATION_MESSAGE);
}
bringToBack(_tgc);
bringToBack(_tgc.getTopFather());
for (int i = 0; i < componentList.size(); i ++){
if (componentList.get(i) instanceof TGConnector) {
TGComponent t = componentList.get(i);
......@@ -2536,10 +2573,10 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
public int getMaxIdSelected() {
int ret = 0;
for (TGComponent tgc : this.componentList)
//issue 186
for (TGComponent tgc : this.getAllComponent())
if (tgc.isSelected())
ret = Math.max(ret, tgc.getMaxId());
return ret;
}
......
......@@ -3079,12 +3079,12 @@ public abstract class TGComponent extends AbstractCDElement implements /*CDElem
// saving
public StringBuffer saveInXML() {
return saveInXML(true);
return saveInXML(true, false);
}
protected StringBuffer saveInXML(boolean saveSubComponents) {
protected StringBuffer saveInXML(boolean saveSubComponents, boolean saveAsComponentEvenIfNonNullFather) {
StringBuffer sb = null;
boolean b = (father == null);
boolean b = (father == null) || saveAsComponentEvenIfNonNullFather;
if (b) {
sb = new StringBuffer(XML_HEAD);
} else {
......@@ -3362,7 +3362,7 @@ public abstract class TGComponent extends AbstractCDElement implements /*CDElem
}
public void searchForText(String text, Vector<Object> elements) {
String save = saveInXML(false).toString().toLowerCase();
String save = saveInXML(false, false).toString().toLowerCase();
if (save.indexOf(text) >= 0) {
//TraceManager.addDev("Found " + this);
elements.add(this);
......
......@@ -727,8 +727,9 @@ public abstract class TGConnector extends TGCScalableWithInternalComponent {
}
@Override
public StringBuffer saveInXML() {
public StringBuffer saveInXML(boolean saveSubComponents, boolean saveAsComponentEvenIfNonNullFather) {
StringBuffer sb = new StringBuffer(XML_CONNECTOR_HEAD);
sb.append(getType());
sb.append(XML_ID);
......
......@@ -15,8 +15,12 @@ import static org.junit.Assert.*;
public class TDiagramPanelCloneTest extends AbstractUITest {
static TDiagramPanel diagramPanel;
static TGComponent tgComponent;
final static String EXPECTED_FILE = getBaseResourcesDir() + "tmltranslator/expected/expected_spec.tml";
static TGComponent tgComponent1;
static TGComponent tgComponent2;
static TGComponent tgComponent3;
final static String EXPECTED_FILE1 = getBaseResourcesDir() + "tmltranslator/expected/expected_spec1.tml";
final static String EXPECTED_FILE2 = getBaseResourcesDir() + "tmltranslator/expected/expected_spec2.tml";
final static String EXPECTED_FILE3 = getBaseResourcesDir() + "tmltranslator/expected/expected_spec3.tml";
@BeforeClass
......@@ -45,23 +49,58 @@ public class TDiagramPanelCloneTest extends AbstractUITest {
}
}
//tgComponent = findDiagComponent(238, diagramPanel);
for (TGComponent tgc : diagramPanel.getComponentList()) {
if (tgc instanceof TMLCCompositeComponent) {
tgComponent = tgc;
for (TGComponent tgc : diagramPanel.getAllComponent()) {
if (tgc.getValue().equals("CompositeComp1")) {
tgComponent1 = tgc;
}
if (tgc.getValue().equals("CompositeComp2")) {
tgComponent2 = tgc;
}
if (tgc.getValue().equals("PrimitiveComp5")) {
tgComponent3 = tgc;
}
}
}
@Test
public void testCloneComponent() throws Exception{
@Test
public void testCloneCompositeComponentWithNullFather() throws Exception{
CompareTML compTML = new CompareTML();
diagramPanel.cloneComponent(tgComponent);
diagramPanel.cloneComponent(tgComponent1);
// mainGUI.modelChecking();
mainGUI.checkModelingSyntax(true);
mainGUI.generateTMLTxt();
File f1 = new File(EXPECTED_FILE);
File f1 = new File(EXPECTED_FILE1);
File f2 = new File("spec.tml"); // Generated file after executing "TML generation"
assertTrue(compTML.compareTML(f1,f2));
}
@Test
public void testCloneCompositeComponentWithNonNullFather() throws Exception {
CompareTML compTML = new CompareTML();
diagramPanel.cloneComponent(tgComponent2);
// mainGUI.modelChecking();
mainGUI.checkModelingSyntax(true);
mainGUI.generateTMLTxt();
File f1 = new File(EXPECTED_FILE2);
File f2 = new File("spec.tml"); // Generated file after executing "TML generation"
assertTrue(compTML.compareTML(f1,f2));
}
@Test
public void testClonePrimitiveComponent() throws Exception {
CompareTML compTML = new CompareTML();
diagramPanel.cloneComponent(tgComponent3);
// mainGUI.modelChecking();
mainGUI.checkModelingSyntax(true);
mainGUI.generateTMLTxt();
File f1 = new File(EXPECTED_FILE3);
File f2 = new File("spec.tml"); // Generated file after executing "TML generation"
assertTrue(compTML.compareTML(f1,f2));
}
}
\ No newline at end of file
// TML Application - FORMAT 0.1
// Application: /home/pham/Documents/TToolHelp/TTool/modeling/DIPLODOCUS/CloneCompositeComponentTest.xml
// Generated: Wed Mar 20 17:19:43 CET 2019
// Channels
CHANNEL DIPLODOCUS_C_Design__channel BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp1 IN DIPLODOCUS_C_Design__PrimitiveComp2
CHANNEL DIPLODOCUS_C_Design__channel2 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp3 IN DIPLODOCUS_C_Design__PrimitiveComp4
CHANNEL DIPLODOCUS_C_Design__channel2_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp3_0 IN DIPLODOCUS_C_Design__PrimitiveComp4_0
CHANNEL DIPLODOCUS_C_Design__channel3 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5 IN DIPLODOCUS_C_Design__PrimitiveComp5
CHANNEL DIPLODOCUS_C_Design__channel3_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5_0 IN DIPLODOCUS_C_Design__PrimitiveComp5_0
CHANNEL DIPLODOCUS_C_Design__channel_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp1_0 IN DIPLODOCUS_C_Design__PrimitiveComp2_0
// Events
EVENT DIPLODOCUS_C_Design__event_0__DIPLODOCUS_C_Design__event_0() NIB 8 DIPLODOCUS_C_Design__PrimitiveComp1_0 DIPLODOCUS_C_Design__PrimitiveComp2_0
EVENT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event() NIB 8 DIPLODOCUS_C_Design__PrimitiveComp1 DIPLODOCUS_C_Design__PrimitiveComp2
// Requests
TASK DIPLODOCUS_C_Design__PrimitiveComp1
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
NOTIFY DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
WRITE DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp1_0
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
NOTIFY DIPLODOCUS_C_Design__event_0__DIPLODOCUS_C_Design__event_0
ENDCASERAND
CASERAND 50
WRITE DIPLODOCUS_C_Design__channel_0 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp2
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
WAIT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
READ DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp2_0
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
WAIT DIPLODOCUS_C_Design__event_0__DIPLODOCUS_C_Design__event_0
ENDCASERAND
CASERAND 50
READ DIPLODOCUS_C_Design__channel_0 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp3
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel2 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp3_0
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel2_0 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp4
TASKOP
//Local variables
//Behavior
READ DIPLODOCUS_C_Design__channel2 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp4_0
TASKOP
//Local variables
//Behavior
READ DIPLODOCUS_C_Design__channel2_0 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp5
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel3 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp5_0
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel3_0 1
ENDTASK
// TML Application - FORMAT 0.1
// Application: /home/pham/Documents/TToolHelp/TTool/modeling/DIPLODOCUS/CloneCompositeComponentTest.xml
// Generated: Wed Mar 20 17:20:10 CET 2019
// Channels
CHANNEL DIPLODOCUS_C_Design__channel BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp1 IN DIPLODOCUS_C_Design__PrimitiveComp2
CHANNEL DIPLODOCUS_C_Design__channel2 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp3 IN DIPLODOCUS_C_Design__PrimitiveComp4
CHANNEL DIPLODOCUS_C_Design__channel2_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp3_0 IN DIPLODOCUS_C_Design__PrimitiveComp4_0
CHANNEL DIPLODOCUS_C_Design__channel3 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5 IN DIPLODOCUS_C_Design__PrimitiveComp5
CHANNEL DIPLODOCUS_C_Design__channel3_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5_0 IN DIPLODOCUS_C_Design__PrimitiveComp5_0
// Events
EVENT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event() NIB 8 DIPLODOCUS_C_Design__PrimitiveComp1 DIPLODOCUS_C_Design__PrimitiveComp2
// Requests
TASK DIPLODOCUS_C_Design__PrimitiveComp1
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
NOTIFY DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
WRITE DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp2
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
WAIT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
READ DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp3
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel2 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp3_0
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel2_0 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp4
TASKOP
//Local variables
//Behavior
READ DIPLODOCUS_C_Design__channel2 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp4_0
TASKOP
//Local variables
//Behavior
READ DIPLODOCUS_C_Design__channel2_0 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp5
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel3 1
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp5_0
TASKOP
//Local variables
//Behavior
WRITE DIPLODOCUS_C_Design__channel3_0 1
ENDTASK
// TML Application - FORMAT 0.1
// Application: /home/pham/Documents/TToolHelp/TTool/modeling/DIPLODOCUS/CloneCompositeComponentTest.xml
// Generated: Wed Mar 20 17:20:50 CET 2019
// Channels
CHANNEL DIPLODOCUS_C_Design__channel BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp1 IN DIPLODOCUS_C_Design__PrimitiveComp2
CHANNEL DIPLODOCUS_C_Design__channel2 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp3 IN DIPLODOCUS_C_Design__PrimitiveComp4
CHANNEL DIPLODOCUS_C_Design__channel3 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5 IN DIPLODOCUS_C_Design__PrimitiveComp5
CHANNEL DIPLODOCUS_C_Design__channel3_0 BRBW 4 8 OUT DIPLODOCUS_C_Design__PrimitiveComp5_0 IN DIPLODOCUS_C_Design__PrimitiveComp5_0
// Events
EVENT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event() NIB 8 DIPLODOCUS_C_Design__PrimitiveComp1 DIPLODOCUS_C_Design__PrimitiveComp2
// Requests
TASK DIPLODOCUS_C_Design__PrimitiveComp1
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
NOTIFY DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
WRITE DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK
TASK DIPLODOCUS_C_Design__PrimitiveComp2
TASKOP
//Local variables
//Behavior
RAND
CASERAND 50
WAIT DIPLODOCUS_C_Design__event__DIPLODOCUS_C_Design__event
ENDCASERAND
CASERAND 50
READ DIPLODOCUS_C_Design__channel 1
ENDCASERAND
ENDRAND
ENDTASK