Skip to content
Snippets Groups Projects
Commit f46c1c75 authored by tolgayurt's avatar tolgayurt
Browse files

added polygoncreator function in the view and buttons fpr it in the index.html template

parent 76dd9b6b
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,7 @@ Polygon
[(686.0, 0.0), (1101.9999999999995, 905.0), (1291.9999999999995, 62.0), (686.0, 0.0)]
[(1842.7583497053038, 0.0), (1286.7583497053042, 4.0), (1332.7583497053042, 513.0), (2047.7583497053038, 608.0), (2023.7583497053038, 423.0), (1842.7583497053038, 0.0)]
[(316.9999999999998, 905.0), (0.0, 1490.0), (356.9999999999998, 1527.0), (741.9999999999998, 1428.0), (724.9999999999998, 1078.0), (316.9999999999998, 905.0)]
[(586.0, 1527.0), (0.0, 1540.0), (300.0, 1762.0), (586.0, 1527.0)]
\ No newline at end of file
[(586.0, 1527.0), (0.0, 1540.0), (300.0, 1762.0), (586.0, 1527.0)]
[(27.26304579339723, 1762.0), (8.413205537806178, 1763.8987341772151), (0.0, 1788.26582278481), (1.490947816826413, 1799.6582278481012), (7.8807241746538885, 1800.0801687763712), (51.43769968051117, 1795.649789029536), (27.26304579339723, 1762.0)]
[(4.1324156191531145, 1800.0801687763712), (0.0, 1810.483927967384), (13.756594100601824, 1811.809503462764), (13.267229093070533, 1804.739767487404), (4.1324156191531145, 1800.0801687763712)]
[(0.05437388972569579, 1811.809503462764), (0.0, 1817.1519743986896), (9.406682922545912, 1816.3485953105805), (8.482326797209026, 1813.6171064110094), (0.05437388972569579, 1811.809503462764)]
\ No newline at end of file
......@@ -34,9 +34,20 @@
{% csrf_token %}
<label for="load_csv_polygons"><b>Load CSV Polygons into PolyEditTool</b></label>
<input id="load_csv_polygons" type="hidden" name="load_csv_polygons" value="test">
<input type="submit" value="load">
<input type="submit" value="load to Drawtool">
</form>
</div>
<div>
<form action="/create_convex_polygons/" target="_blank" method="post">
{% csrf_token %}
<label for="polygon_count"><b>Create Random Polygons, Number of Polygons</b></label>
<input id="polygon_count" type="number" min="0" name="polygon_count" value=5>
<label for="vertices"><b>Number of Vertices (min 3)</b></label>
<input id="vertices" type="number" min="3" name="vertices" value=10>
<input type="submit" value="load to Drawtool">
</form>
</div>
<div>
<form action="/packing_rect_container/" target="_blank" method="get">
{% csrf_token %}
......
......@@ -14,7 +14,7 @@
{% endautoescape %}
</div>
<div>
<h1>Final Container Polygon Coordinates</h1>
<h1>Final Container Polygons Coordinates</h1>
<p>every Row stands for one Polygon<p>
{% for polygon in coordinates%}
{{polygon}}<br>
......
from django.urls import path
from plots.views import PolygonEditView, PackingRectContainer, PackingRotatedRectContainer, PackingConvexContainer, \
CSVPolygons, ClearPolygons
CSVPolygons, ClearPolygons ,CreateConvexPolygons
from . import views
urlpatterns = [
......@@ -14,4 +14,5 @@ urlpatterns = [
path('packing_convex_container/', PackingConvexContainer.as_view(), name='convex_container'),
path('csv_polygons/', CSVPolygons.as_view(), name='csv_polygons'),
path('clear_polygons/', ClearPolygons.as_view(), name='csv_polygons'),
]
\ No newline at end of file
path('create_convex_polygons/', CreateConvexPolygons.as_view(), name='create_convex_polygons'),
]
......@@ -73,6 +73,7 @@ class PackingRectContainer(View):
class PackingRotatedRectContainer(View):
def get(self, request, *args, **kwargs):
coordinates = []
if PolygonEditView.polygons==[]:
plot_steps_html = "No Polygon"
else:
......@@ -85,14 +86,7 @@ class PackingRotatedRectContainer(View):
"coordinates":coordinates})
class PackingConvexContainer(View):
# context = {}
# def get(self, request, *args, **kwargs):
#
# cc = poly.ConvexContainer(PolygonEditView.polygons, steps=1)
# plot_steps = cc.plot_steps(render=False)
# plot_steps_html = file_html(plot_steps, CDN, "my plot23")
# # PackingPolygons.context["packed_polygons"]=plot_steps_html
# return render(request, 'plots/packed_polygons.html', context={"plot_steps": plot_steps_html})
coordinates = []
def post(self, request, *args, **kwargs):
if PolygonEditView.polygons==[]:
plot_steps_html = "No Polygon"
......@@ -119,8 +113,31 @@ class ClearPolygons(View):
PolygonEditView.plot_min_y = 0
return HttpResponseRedirect('/index/')
class CreateConvexPolygons(View):
def post(self, request, *args, **kwargs):
max_vertices_count = int(request.POST["vertices"])
polygon_count = int(request.POST["polygon_count"])
polygons = poly.create_multiple_convex_polygons(polygon_count,max_vertices_count)
all_x_values = [PolygonEditView.plot_max_x, PolygonEditView.plot_min_x]
all_y_values = [PolygonEditView.plot_min_y,PolygonEditView.plot_max_y]
for polygon in polygons:
all_x_values = all_x_values + polygon.x_values
all_y_values = all_y_values + polygon.y_values
PolygonEditView.colum_data_x.append(polygon.x_values)
PolygonEditView.colum_data_y.append(polygon.y_values)
PolygonEditView.plot_max_x = max(all_x_values)
PolygonEditView.plot_min_x = min(all_x_values)
PolygonEditView.plot_max_y = max(all_y_values)
PolygonEditView.plot_min_y = min(all_y_values)
return HttpResponseRedirect('/index/')
class CSVPolygons(View):
def get(self,request,):
def get(self, request):
PolygonEditView.csv_polygons = []
PolygonEditView.polygons = PolygonEditView.drawn_polygons
PolygonEditView.context["csv_polygons"] = "Cleared"
......@@ -137,8 +154,8 @@ class CSVPolygons(View):
def post(self, request, *args, **kwargs):
df = pandas.read_csv('plots/polygon.txt',sep="#")
csv_polygons = df["Polygon"]
all_x_values = []
all_y_values = []
all_x_values = [PolygonEditView.plot_max_x, PolygonEditView.plot_min_x]
all_y_values = [PolygonEditView.plot_min_y,PolygonEditView.plot_max_y]
for polygon_str in csv_polygons:
polygon = eval(polygon_str)
x_tuples, y_tuples = (zip(*polygon))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment