mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Fixed issues when creating leaded components using drag and drop with
'Snap to Grid' option switched on using a metric grid spacing (e.g. 1mm)
This commit is contained in:
@@ -32,6 +32,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
/**
|
||||
@@ -259,4 +260,9 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public Rectangle2D getCachingBounds() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createdIn(Project project) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,4 +197,11 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
|
||||
* @return
|
||||
*/
|
||||
Rectangle2D getCachingBounds();
|
||||
|
||||
/**
|
||||
* Notifies the component that it's being created in the context of the specified project
|
||||
*
|
||||
* @param project
|
||||
*/
|
||||
void createdIn(Project project);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.text.Format;
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class AbstractMeasure<T extends Enum<? extends Unit>> implements Serializable, Cloneable {
|
||||
public abstract class AbstractMeasure<T extends Enum<? extends Unit>> implements Serializable, Cloneable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -48,6 +48,13 @@ public class CalcUtils {
|
||||
point.setLocation(x, y);
|
||||
}
|
||||
|
||||
public static Size findClosestMultiplierOf(Size factor, Size target, int step) {
|
||||
Size ret = new Size(0d, factor.getUnit());
|
||||
while (ret.convertToPixels() < target.convertToPixels())
|
||||
ret = new Size(ret.getValue() + factor.getValue() * step, factor.getUnit());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void snapPointToObjects(Point2D point, Size gridSpacing, IDIYComponent<?> component, List<IDIYComponent<?>> components) {
|
||||
for (IDIYComponent<?> c : components) {
|
||||
if (c == component)
|
||||
|
||||
@@ -261,6 +261,7 @@ public class InstantiationManager {
|
||||
|
||||
// Instantiate the component.
|
||||
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
||||
component.createdIn(currentProject);
|
||||
|
||||
component.setName(createUniqueName(componentType, currentProject.getComponents()));
|
||||
|
||||
|
||||
@@ -3290,6 +3290,10 @@
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>macOS: two finger click shows the popup menu without deselecting a selected component</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Fixed issues when creating leaded components using drag and drop with 'Snap to Grid' option switched on using a metric grid spacing (e.g. 1mm)</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Do not allow for components like traces, jumpers and wires to be reduced to nothing by dragging connected components</description>
|
||||
@@ -3300,7 +3304,7 @@
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Moving a rigid component (e.g. tube/transistor symbol) which is not snapped to grid makes it snap back to the grid when 'Snap to Grid' is switched on</description>
|
||||
<description>Moving a rigid component (e.g. tube/transistor symbol) which is not snapped to grid makes it snap back to the grid when 'Snap to Grid' option is switched on</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
|
||||
Binary file not shown.
@@ -52,6 +52,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.PositiveNonZeroMeasureValidator;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.presenter.CalcUtils;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
/**
|
||||
@@ -103,6 +104,13 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
points[2] = calculateLabelPosition(points[0], points[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createdIn(Project project) {
|
||||
double targetSize = CalcUtils.findClosestMultiplierOf(project.getGridSpacing(), DEFAULT_SIZE, 2).convertToPixels();
|
||||
points[0]= new Point2D.Double(-targetSize / 2, 0);
|
||||
points[1] = new Point2D.Double(targetSize / 2, 0);
|
||||
}
|
||||
|
||||
protected boolean IsCopperArea() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user