Assign new name for pasted component if the project already contains

components under that name
This commit is contained in:
Branislav Stojkovic
2019-03-20 22:35:28 +01:00
parent 78dcd27e1d
commit 894ff1a2cb
4 changed files with 30 additions and 6 deletions
@@ -27,8 +27,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
@@ -139,16 +141,34 @@ public class InstantiationManager {
return changeMade;
}
@SuppressWarnings("unchecked")
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
Size gridSpacing, boolean autoGroup) {
Size gridSpacing, boolean autoGroup, Project currentProject) {
// Adjust location of components so they are centered under the mouse
// cursor
int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (IDIYComponent<?> component : components) {
for (int i = 0; i < component.getControlPointCount(); i++) {
int maxY = Integer.MIN_VALUE;
Set<String> existingNames = new HashSet<String>();
for (IDIYComponent<?> c : currentProject.getComponents())
existingNames.add(c.getName());
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
for (IDIYComponent<?> component : components) {
// assign a new name if it already exists in the project
if (existingNames.contains(component.getName())) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass());
String newName = createUniqueName(componentType, allComponents);
existingNames.add(newName);
component.setName(newName);
allComponents.add(component);
}
for (int i = 0; i < component.getControlPointCount(); i++) {
Point p = component.getControlPoint(i);
if (p.x > maxX) {
maxX = p.x;
@@ -1532,7 +1532,7 @@ public class Presenter implements IPlugInPort {
public void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup) {
LOG.info(String.format("pasteComponents(%s, %s)", components, autoGroup));
instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(),
currentProject.getGridSpacing(), autoGroup);
currentProject.getGridSpacing(), autoGroup, this.currentProject);
messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(),
instantiationManager.getFirstControlPoint());
Binary file not shown.
+5 -1
View File
@@ -2638,6 +2638,10 @@
<changeType>IMPROVEMENT</changeType>
<description>Ability to show labels for standing components and control the position</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Assign a new name for pasted component if the project already contains components under that name</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Output SPICE node names in the "Nxxx" format</description>
@@ -2664,7 +2668,7 @@
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Some schematic symbols (transistors, potentiometer...) get into bad state when rotated and flipped at the same time</description>
<description>Some schematic symbols (transistors, potentiometer...) are not rendered properly when rotated and flipped at the same time</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>