Skip to content

Commit

Permalink
Merge pull request #129 from Akhetonics/feature/Tools
Browse files Browse the repository at this point in the history
Feature/tools
  • Loading branch information
aignermax committed Mar 19, 2024
2 parents abc14b0 + b0695b8 commit 09de7a5
Show file tree
Hide file tree
Showing 20 changed files with 570 additions and 88 deletions.
Binary file added GFX/SelectTool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions GFX/SelectTool.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bekjifiu8efnt"
path="res://.godot/imported/SelectTool.png-03f1b6a1ce010ab1efc066c94acce94f.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://GFX/SelectTool.png"
dest_files=["res://.godot/imported/SelectTool.png-03f1b6a1ce010ab1efc066c94acce94f.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
80 changes: 65 additions & 15 deletions PDK/test3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import nazca as nd
from TestPDK import TestPDK

Expand All @@ -8,20 +7,71 @@ def FullDesign(layoutName):
with nd.Cell(name=layoutName) as fullLayoutInner:

grating = CAPICPDK.placeGratingArray_East(8).put(0, 0)

cell_0_2 = CAPICPDK.placeCell_StraightWG().put('west', grating.pin['io1'])
cell_1_2 = CAPICPDK.placeCell_GratingCoupler().put('west', cell_0_2.pin['east'])
cell_0_3 = CAPICPDK.placeCell_StraightWG().put('west', grating.pin['io2'])
cell_1_3 = CAPICPDK.placeCell_StraightWG().put('west', cell_0_3.pin['east'])
cell_2_3 = CAPICPDK.placeCell_GratingCoupler().put('west', cell_1_3.pin['east'])
cell_0_4 = CAPICPDK.placeCell_StraightWG().put('west', grating.pin['io3'])
cell_1_4 = CAPICPDK.placeCell_StraightWG().put('west', cell_0_4.pin['east'])
cell_2_4 = CAPICPDK.placeCell_StraightWG().put('west', cell_1_4.pin['east'])
cell_3_4 = CAPICPDK.placeCell_GratingCoupler().put('west', cell_2_4.pin['east'])
cell_7_4 = CAPICPDK.placeCell_DirectionalCoupler(deltaLength = 50).put((7)*CAPICPDK._CellSize , (-4)*CAPICPDK._CellSize )
cell_8_4 = CAPICPDK.placeCell_StraightWG().put('west', cell_7_4.pin['east0'])
cell_9_4 = CAPICPDK.placeCell_GratingCoupler().put('west', cell_8_4.pin['east'])
cell_0_2 = CAPICPDK.placeCell_StraightWG().put('west', grating.pin['io0'])
cell_1_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_0_2.pin['east'])
cell_2_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_1_2.pin['east'])
cell_3_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_2_2.pin['east'])
cell_4_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_3_2.pin['east'])
cell_5_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_4_2.pin['east'])
cell_6_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_5_2.pin['east'])
cell_7_2 = CAPICPDK.placeCell_MMI3x3().put('west0', cell_6_2.pin['east'])
cell_4_3 = CAPICPDK.placeCell_MMI3x3().put('west2', cell_7_2.pin['west1'])
cell_1_3 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_4_3.pin['east2'])
cell_0_3 = CAPICPDK.placeCell_StraightWG().put('east', cell_1_3.pin['west0'])
cell_0_4 = CAPICPDK.placeCell_StraightWG().put('east', cell_1_3.pin['west1'])
cell_0_5 = CAPICPDK.placeCell_StraightWG().put('east', cell_1_3.pin['west2'])
cell_7_5 = CAPICPDK.placeCell_StraightWG().put('east', cell_4_3.pin['west0'])
cell_8_5 = CAPICPDK.placeCell_StraightWG().put('east', cell_7_5.pin['west'])
cell_9_5 = CAPICPDK.placeCell_StraightWG().put('east', cell_8_5.pin['west'])
cell_10_3 = CAPICPDK.placeCell_MMI3x3().put('west2', cell_9_5.pin['west'])
cell_13_3 = CAPICPDK.placeCell_MMI3x3().put('west0', cell_10_3.pin['east0'])
cell_16_3 = CAPICPDK.placeCell_MMI3x3().put('west0', cell_13_3.pin['east0'])
cell_19_3 = CAPICPDK.placeCell_BendWG().put('west', cell_16_3.pin['east0'])
cell_19_4 = CAPICPDK.placeCell_BendWG().put('west', cell_19_3.pin['south'])
cell_19_5 = CAPICPDK.placeCell_BendWG().put('west', cell_16_3.pin['east2'])
cell_19_6 = CAPICPDK.placeCell_StraightWG().put('west', cell_19_5.pin['south'])
cell_19_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_19_6.pin['east'])
cell_17_8 = CAPICPDK.placeCell_MMI3x3().put('east2', cell_19_7.pin['east'])
cell_18_7 = CAPICPDK.placeCell_BendWG().put('south', cell_17_8.pin['east1'])
cell_17_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_18_7.pin['west'])
cell_16_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_17_7.pin['east'])
cell_15_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_16_7.pin['east'])
cell_14_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_15_7.pin['east'])
cell_13_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_14_7.pin['east'])
cell_12_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_13_7.pin['east'])
cell_11_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_12_7.pin['east'])
cell_8_6 = CAPICPDK.placeCell_MMI3x3().put('east1', cell_11_7.pin['east'])
cell_5_6 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_8_6.pin['west0'])
cell_2_6 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_5_6.pin['west0'])
cell_1_7 = CAPICPDK.placeCell_BendWG().put('south', cell_2_6.pin['west1'])
cell_1_8 = CAPICPDK.placeCell_BendWG().put('south', cell_1_7.pin['west'])
cell_11_8 = CAPICPDK.placeCell_MMI3x3().put('west0', cell_8_6.pin['east2'])
cell_8_9 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_11_8.pin['west1'])
cell_5_9 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_8_9.pin['west0'])
cell_2_9 = CAPICPDK.placeCell_MMI3x3().put('east0', cell_5_9.pin['west0'])
cell_14_8 = CAPICPDK.placeCell_MMI3x3().put('west0', cell_11_8.pin['east0'])
cell_19_11 = CAPICPDK.placeCell_BendWG().put('south', cell_17_8.pin['west2'])
cell_20_11 = CAPICPDK.placeCell_BendWG().put('south', cell_19_11.pin['west'])
cell_20_10 = CAPICPDK.placeCell_StraightWG().put('west', cell_20_11.pin['west'])
cell_20_9 = CAPICPDK.placeCell_StraightWG().put('west', cell_20_10.pin['east'])
cell_20_8 = CAPICPDK.placeCell_StraightWG().put('west', cell_20_9.pin['east'])
cell_20_7 = CAPICPDK.placeCell_StraightWG().put('west', cell_20_8.pin['east'])
cell_20_6 = CAPICPDK.placeCell_StraightWG().put('east', cell_20_7.pin['east'])
cell_20_5 = CAPICPDK.placeCell_StraightWG().put('east', cell_20_6.pin['west'])
cell_20_4 = CAPICPDK.placeCell_StraightWG().put('east', cell_20_5.pin['west'])
cell_20_3 = CAPICPDK.placeCell_StraightWG().put('east', cell_20_4.pin['west'])
cell_20_2 = CAPICPDK.placeCell_BendWG().put('south', cell_20_3.pin['west'])
cell_19_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_20_2.pin['west'])
cell_18_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_19_2.pin['east'])
cell_17_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_18_2.pin['east'])
cell_16_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_17_2.pin['east'])
cell_15_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_16_2.pin['east'])
cell_14_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_15_2.pin['east'])
cell_13_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_14_2.pin['east'])
cell_12_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_13_2.pin['east'])
cell_11_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_12_2.pin['east'])
cell_10_2 = CAPICPDK.placeCell_StraightWG().put('west', cell_11_2.pin['east'])
return fullLayoutInner

nd.print_warning = False
nd.export_gds(topcells=FullDesign("Akhetonics_ConnectAPIC"), filename="Test.gds")
nd.export_gds(topcells=FullDesign("Akhetonics_ConnectAPIC"), filename="TestPDK.py")
8 changes: 4 additions & 4 deletions Scenes/PICEditor/PICEditor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ InGameConsole = NodePath("GUILayer/InGameConsole")
script = ExtResource("2_7hjmy")
ComponentBaseScriptPath = ExtResource("3_celc4")

[node name="NotificationManager" type="Node" parent="."]
script = ExtResource("9_gj54m")
NotificationBoxScene = ExtResource("10_06t00")

[node name="GridView" type="TileMap" parent="." node_paths=PackedStringArray("DragDropProxy", "ComponentViewFactory", "LightOnButton")]
texture_filter = 1
position = Vector2(155.395, 42.7)
Expand Down Expand Up @@ -194,6 +190,10 @@ size_flags_horizontal = 6
size_flags_vertical = 6
ToggleButton = NodePath("../MenuBar/HBoxContainer/btnHelp")

[node name="NotificationManager" type="Node" parent="GUILayer"]
script = ExtResource("9_gj54m")
NotificationBoxScene = ExtResource("10_06t00")

[connection signal="pressed" from="GUILayer/MenuBar/HBoxContainer/btnSave" to="GridView" method="_on_btn_save_pressed"]
[connection signal="pressed" from="GUILayer/MenuBar/HBoxContainer/btnLoad" to="GridView" method="_on_btn_load_pressed"]
[connection signal="toggled" from="GUILayer/MenuBar/HBoxContainer/btnShowLightPropagation" to="GridView" method="_on_btn_show_light_propagation_toggled"]
Expand Down
2 changes: 1 addition & 1 deletion Scenes/RightClickMenu/RightClickMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void _Ready()
}


public override void _Input(InputEvent @event)
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventMouseButton mouseButton) {
if (mouseButton.IsPressed() && mouseIn) {
Expand Down
5 changes: 3 additions & 2 deletions Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ConnectAPic.LayoutWindow
[SuperNode(typeof(Provider))]
public partial class GameManager : Node,
IProvide<ToolBox>, IProvide<ILogger>, IProvide<GridView>, IProvide<GridManager>, IProvide<GridViewModel>, IProvide<GameManager>,
IProvide<GameConsole>, IProvide<System.Version>, IProvide<ComponentViewFactory>, IProvide<LightCalculationService>
IProvide<GameConsole>, IProvide<System.Version>, IProvide<ComponentViewFactory>, IProvide<LightCalculationService>, IProvide<ToolViewModel>
{
#region Dependency Injection
public override partial void _Notification(int what);
Expand All @@ -36,6 +36,7 @@ public partial class GameManager : Node,
GridView IProvide<GridView>.Value() => GridView;
GridManager IProvide<GridManager>.Value() => Grid;
GridViewModel IProvide<GridViewModel>.Value() => GridViewModel;
ToolViewModel IProvide<ToolViewModel>.Value() => GridViewModel.ToolViewModel;
GameManager IProvide<GameManager>.Value() => this;
GameConsole IProvide<GameConsole>.Value() => InGameConsole;
ComponentViewFactory IProvide<ComponentViewFactory>.Value() => GridView.ComponentViewFactory;
Expand All @@ -51,7 +52,7 @@ public partial class GameManager : Node,
[Export] public int FieldHeight { get; set; } = 12;
[Export] public GameConsole InGameConsole { get; set; }
private PCKLoader PCKLoader { get; set; }
public static int TilePixelSize { get; private set; } = 62;
public static int TilePixelSize { get; private set; } = 62; // the tile size including the border
public static int TileBorderLeftDown { get; private set; } = 2;
public GridView GridView { get; set; }
public PortsContainer PortsContainer { get; set; }
Expand Down
31 changes: 25 additions & 6 deletions Scripts/View/ComponentViews/ComponentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace ConnectAPIC.LayoutWindow.View
{
public partial class ComponentView : TextureRect
{
private const float DragThreshold = 5.0f;
public int WidthInTiles { get; set; }
public int HeightInTiles { get; set; }
private Node2D RotationArea { get; set; } // the part of the component that rotates
Expand All @@ -45,6 +46,7 @@ public partial class ComponentView : TextureRect
private new float Rotation { get => RotationArea.Rotation; set => RotationArea.Rotation = value; }
public SliderManager SliderManager { get; }
public OverlayManager OverlayManager { get; set; }
public Vector2 InitialClickPosition { get; private set; }

public ComponentView()
{
Expand Down Expand Up @@ -116,23 +118,40 @@ public override void _GuiInput(InputEvent inputEvent)
}
if (mouseEvent.ButtonIndex == MouseButton.Middle && mouseEvent.Pressed)
{
ViewModel.DeleteComponentCommand?.ExecuteAsync(new DeleteComponentArgs(ViewModel.GridX, ViewModel.GridY)).RunSynchronously();
ViewModel.DeleteComponentCommand?.ExecuteAsync(new DeleteComponentArgs(ViewModel.GridX, ViewModel.GridY)).Wait();
}
if (mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed)
if (mouseEvent.ButtonIndex == MouseButton.Right)
{
var args = new RotateComponentArgs(ViewModel.GridX, ViewModel.GridY);
if (ViewModel.RotateComponentCommand?.CanExecute(args) == true)
if (mouseEvent.Pressed)
{
ViewModel.RotateComponentCommand?.ExecuteAsync(args).RunSynchronously();
InitialClickPosition = mouseEvent.GlobalPosition;
}
else
{
// Error Animation
float dragDistance = InitialClickPosition.DistanceTo(mouseEvent.GlobalPosition);
if (dragDistance <= DragThreshold)
{
TryRotateComponent();
}
}

}
}
}

private void TryRotateComponent()
{
var args = new RotateComponentArgs(ViewModel.GridX, ViewModel.GridY);
if (ViewModel.RotateComponentCommand?.CanExecute(args) == true)
{
ViewModel.RotateComponentCommand?.ExecuteAsync(args).Wait();
}
else
{
// Error Animation
}
}

public virtual ComponentView Duplicate()
{
var copy = (ComponentView)base.Duplicate();
Expand Down
7 changes: 7 additions & 0 deletions Scripts/View/DragDropProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class DragDropProxy : Control
public delegate Variant GetDragData(Vector2 position);
public delegate bool CanDropData(Vector2 position, Variant data);
public delegate void DropData(Vector2 position, Variant data);
public event EventHandler<InputEvent> InputReceived;
public event GetDragData OnGetDragData;
public event CanDropData OnCanDropData;
public event DropData OnDropData;
Expand Down Expand Up @@ -82,4 +83,10 @@ private void CheckIfDragWasReset()
DragPreview = null;
}
}

public override void _Input(InputEvent @event)
{
base._Input(@event);
InputReceived?.Invoke(this, @event);
}
}
5 changes: 4 additions & 1 deletion Scripts/View/GridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class GridView : TileMap
[Export] private Texture2D LightOffTexture;
[Export] private Button LightOnButton;

private GridViewModel ViewModel;
public GridViewModel ViewModel;
public ComponentView[,] GridComponentViews { get; private set; }
public const string GridSaveFileExtensionPatterns = "*.pic";

Expand All @@ -53,6 +53,8 @@ public void Initialize(GridViewModel viewModel, ILogger logger)
DragDropProxy.OnCanDropData += _CanDropData;
DragDropProxy.OnDropData += _DropData;
DragDropProxy.Initialize(viewModel.Width, viewModel.Height);
DragDropProxy.InputReceived += (object sender, InputEvent e) => {
};
viewModel.PropertyChanged += async (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
{
switch (e.PropertyName)
Expand Down Expand Up @@ -83,6 +85,7 @@ public void Initialize(GridViewModel viewModel, ILogger logger)
this.GridComponentViews = new ComponentView[viewModel.Width, viewModel.Height];
CreateEmptyField();
}

public void CreateEmptyField()
{
foreach (var componentView in GridComponentViews)
Expand Down
4 changes: 2 additions & 2 deletions Scripts/View/StandardDialogs/NotificationBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public override void _Ready()
public void ShowMessage(string message, bool isError)
{
messageLabel.Text = message;

if (isError)
{
AddThemeStyleboxOverride("panel", RedStyle);
} else
{
AddThemeStyleboxOverride("panel", GreenStyle);
}

Visible = true;
tween.TweenProperty(this, "modulate:a", 0.9f, 0.25f);
tween.TweenProperty(this, "modulate:a", 1, 1.25f);
Expand Down
2 changes: 1 addition & 1 deletion Scripts/View/StandardDialogs/NotificationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Notify(string message, bool isError = false)
var yOffset = currentlyShownNotifications.Count * notificationBox.Size.Y;
notificationBox.Position = new Vector2( notificationBox.Position.X, notificationBox.Position.Y - yOffset);
currentlyShownNotifications.Add(notificationBox);
GetTree().Root.AddChild(notificationBox);
this.AddChild(notificationBox);
notificationBox.ShowMessage(message, isError);
}

Expand Down
36 changes: 22 additions & 14 deletions Scripts/View/TemplateTileView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class TemplateTileView : TextureRect
{
//[Export] public ComponentViewFactory componentViewFactory { get; set; }
public override partial void _Notification(int what);
public EventHandler Clicked;
[Dependency] public ComponentViewFactory ComponentViewFactory => DependOn<ComponentViewFactory>();
[Dependency] public ILogger Logger => DependOn<ILogger>();
public override void _Ready()
Expand All @@ -23,23 +24,30 @@ public override void _DropData(Vector2 position, Variant data)
{ // you cannot drop something on a template tile
}

public override Variant _GetDragData(Vector2 position)
{
if (GetChild(0) is ComponentView template)
{
var newComponent = ComponentViewFactory.CreateComponentView(template.ViewModel.TypeNumber);
return newComponent;
} else
{
var exceptionText = "child of _GetDragData() is not of type ComponentView even though it should be";
Logger.PrintErr(exceptionText);
throw new DataMisalignedException(exceptionText);
}
}
//public override Variant _GetDragData(Vector2 position)
//{
// if (GetChild(0) is ComponentView template)
// {
// var newComponent = ComponentViewFactory.CreateComponentView(template.ViewModel.TypeNumber);
// return newComponent;
// }
// else
// {
// var exceptionText = "child of _GetDragData() is not of type ComponentView even though it should be";
// Logger.PrintErr(exceptionText);
// throw new DataMisalignedException(exceptionText);
// }
//}

public override void _GuiInput(InputEvent inputEvent)
{
// override so that the tile cannot use middle click and right click
if( inputEvent is InputEventMouseButton mouseButtonEvent)
{
if(mouseButtonEvent.Pressed && mouseButtonEvent.ButtonIndex == MouseButton.Left)
{
Clicked?.Invoke(this , new EventArgs());
}
}
}
}

Expand Down
Loading

0 comments on commit 09de7a5

Please sign in to comment.