Added ability to lock and unlock individual components from the context

menu
This commit is contained in:
bancika
2020-04-19 19:32:50 +02:00
parent 7754922711
commit 7df07c2bd1
9 changed files with 168 additions and 28 deletions
@@ -383,5 +383,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
*
* @param editor
*/
void applyEditor(IProjectEditor editor);
void applyEditor(IProjectEditor editor);
/**
* Locks or unlocks a single component.
*/
void lockComponent(IDIYComponent<?> c, boolean locked);
}
@@ -51,10 +51,11 @@ public interface ISelectionProcessor {
* Finds all components at the specified location, sorted by z-index from top to bottom. Location
* depends on the current zoom level.
*
* @param point
* @param point
* @param includeLocked
* @return
*/
List<IDIYComponent<?>> findComponentsAt(Point point);
List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked);
/**
* Expands the current selection to include surrounding components. Options are controlled with
@@ -67,7 +67,8 @@ public class Project implements Serializable, Cloneable {
private Integer dotSpacing;
private List<IDIYComponent<?>> components;
private Set<Set<IDIYComponent<?>>> groups;
private Set<Integer> lockedLayers;
private Set<Integer> lockedLayers;
private Set<IDIYComponent<?>> lockedComponents;
private Set<Integer> hiddenLayers;
private Font font = DEFAULT_FONT;
@@ -75,7 +76,8 @@ public class Project implements Serializable, Cloneable {
components = new ArrayList<IDIYComponent<?>>();
groups = new HashSet<Set<IDIYComponent<?>>>();
lockedLayers = new HashSet<Integer>();
hiddenLayers = new HashSet<Integer>();
hiddenLayers = new HashSet<Integer>();
lockedComponents = new HashSet<IDIYComponent<?>>();
title = DEFAULT_TITLE;
author = System.getProperty("user.name");
width = DEFAULT_WIDTH;
@@ -165,6 +167,12 @@ public class Project implements Serializable, Cloneable {
*/
public Set<Set<IDIYComponent<?>>> getGroups() {
return groups;
}
public Set<IDIYComponent<?>> getLockedComponents() {
if (lockedComponents == null)
lockedComponents = new HashSet<IDIYComponent<?>>();
return lockedComponents;
}
public Set<Integer> getLockedLayers() {
@@ -289,6 +297,11 @@ public class Project implements Serializable, Cloneable {
return false;
} else if (!lockedLayers.equals(other.lockedLayers))
return false;
if (getLockedComponents() == null) {
if (other.lockedComponents != null)
return false;
} else if (!getLockedComponents().equals(other.lockedComponents))
return false;
if (hiddenLayers == null) {
if (other.hiddenLayers != null)
return false;
@@ -328,14 +341,14 @@ public class Project implements Serializable, Cloneable {
project.setHeight(this.getHeight());
project.setWidth(this.getWidth());
project.getLockedLayers().addAll(this.getLockedLayers());
project.getHiddenLayers().addAll(this.getHiddenLayers());
project.getHiddenLayers().addAll(this.getHiddenLayers());
project.setFont(this.getFont());
Map<IDIYComponent<?>, IDIYComponent<?>> cloneMap = new HashMap<IDIYComponent<?>, IDIYComponent<?>>();
for (IDIYComponent<?> component : this.components) {
try {
IDIYComponent<?> clone = component.clone();
IDIYComponent<?> clone = component.clone();
project.getComponents().add(clone);
cloneMap.put(component, clone);
} catch (CloneNotSupportedException e) {
@@ -349,6 +362,10 @@ public class Project implements Serializable, Cloneable {
cloneGroup.add(cloneMap.get(component));
}
project.groups.add(cloneGroup);
}
for (IDIYComponent<?> component : this.getLockedComponents()) {
project.lockedComponents.add(cloneMap.get(component));
}
return project;
}
@@ -529,12 +529,12 @@ public class Presenter implements IPlugInPort {
*
* @return
*/
public List<IDIYComponent<?>> findComponentsAtScaled(Point point) {
public List<IDIYComponent<?>> findComponentsAtScaled(Point point, boolean includeLocked) {
List<IDIYComponent<?>> components = drawingManager.findComponentsAt(point, currentProject);
Iterator<IDIYComponent<?>> iterator = components.iterator();
while (iterator.hasNext()) {
IDIYComponent<?> component = iterator.next();
if (isComponentLocked(component) || !isComponentVisible(component)) {
if ((includeLocked ? isComponentLayerLocked(component) : isComponentLocked(component)) || !isComponentVisible(component)) {
iterator.remove();
}
}
@@ -542,9 +542,9 @@ public class Presenter implements IPlugInPort {
}
@Override
public List<IDIYComponent<?>> findComponentsAt(Point point) {
public List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked) {
Point scaledPoint = scalePoint(point);
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint);
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint, includeLocked);
return components;
}
@@ -654,7 +654,7 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT);
} else {
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(selectedComponents);
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint);
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint, false);
// If there's nothing under mouse cursor deselect all.
if (components.isEmpty()) {
if (!ctrlDown) {
@@ -1087,7 +1087,7 @@ public class Presenter implements IPlugInPort {
this.preDragProject = currentProject.clone();
Point scaledPoint = scalePoint(point);
this.previousDragPoint = scaledPoint;
List<IDIYComponent<?>> components = forceSelectionRect ? null : findComponentsAtScaled(scaledPoint);
List<IDIYComponent<?>> components = forceSelectionRect ? null : findComponentsAtScaled(scaledPoint, false);
if (controlPointMap != null && !this.controlPointMap.isEmpty()) {
// If we're dragging control points reset selection.
updateSelection(new ArrayList<IDIYComponent<?>>(this.controlPointMap.keySet()));
@@ -2765,9 +2765,41 @@ public class Presenter implements IPlugInPort {
}
return lockedComponents;
}
@Override
public void lockComponent(IDIYComponent<?> c, boolean locked) {
LOG.debug(String.format("lockComponent(%s, %s)", c.getName(), locked));
Project oldProject = currentProject.clone();
try {
if (locked) {
currentProject.getLockedComponents().add(c);
selectedComponents.remove(c);
} else {
currentProject.getLockedComponents().remove(c);
}
} finally {
// Notify the listeners.
if (!oldProject.equals(currentProject)) {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
locked ? "Lock Component" : "Unlock Component");
projectFileManager.notifyFileChange();
}
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (locked)
updateSelection(selectedComponents);
}
}
@SuppressWarnings("unchecked")
private boolean isComponentLocked(IDIYComponent<?> component) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass());
return currentProject.getLockedLayers().contains((int) Math.round(componentType.getZOrder())) || currentProject.getLockedComponents().contains(component);
}
@SuppressWarnings("unchecked")
private boolean isComponentLayerLocked(IDIYComponent<?> component) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass());
@@ -3002,9 +3002,17 @@
<changeType>NEW_FEATURE</changeType>
<description>"Add Flexible Leads" action added in the context menu that replaces straight leads of leaded components with flexible leads and adds leds to some components that do not have them (e.g. Transistors, Tube Sockets, Potentiometers, etc)</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added ability to lock and unlock individual components from the context menu</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added "Rotary Selector Switch" component</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added support for automated regression testing of core functionalities which should reduce regression bugs in the long run</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>