Commit ef4f0236 authored by Minh Hiep Pham's avatar Minh Hiep Pham 💬
Browse files

clone a part of composite component

parent 5a23fca9
......@@ -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, false);
}
/*
* #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,7 @@ 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);
_tgc.select(false);
for(int i = 0; i < connectorList.size(); i++){
......@@ -2536,10 +2572,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);
......
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