wolfhece 2.2.29__py3-none-any.whl → 2.2.31__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,11 @@ from .drawing_obj import Element_To_Draw
53
53
  from .matplotlib_fig import Matplotlib_Figure as MplFig
54
54
  from .PyPalette import wolfpalette
55
55
 
56
+ try:
57
+ from .pydownloader import download_file, toys_dataset
58
+ except ImportError as e:
59
+ raise Exception(_('Error importing pydownloader module'))
60
+
56
61
  class Triangulation(Element_To_Draw):
57
62
  """ Triangulation based on a listof vertices
58
63
  and triangles enumerated by their vertex indices """
@@ -1246,6 +1251,14 @@ class vector:
1246
1251
  if fromnumpy is not None:
1247
1252
  self.add_vertices_from_array(fromnumpy)
1248
1253
 
1254
+ def __add__(self, other:"vector") -> "vector":
1255
+ """ Add two vectors together """
1256
+ if not isinstance(other, vector):
1257
+ raise TypeError("Can only add vector to vector")
1258
+ new_vector = vector(name=self.myname + '_' + other.myname)
1259
+ new_vector.myvertices = self.myvertices.copy() + other.myvertices.copy()
1260
+ return new_vector
1261
+
1249
1262
  def add_value(self, key:str, value:Union[int,float,bool,str]):
1250
1263
  """ Add a value to the properties """
1251
1264
  self.myprop[key] = value
@@ -2594,6 +2607,13 @@ class vector:
2594
2607
  """
2595
2608
  Retrouve le segment associé aux paramètres passés
2596
2609
  """
2610
+
2611
+ if self.length2D is None or self.length3D is None:
2612
+ self.update_lengths()
2613
+ else:
2614
+ if len(self._lengthparts2D) != self.nbvertices-1 or len(self._lengthparts3D) != self.nbvertices-1:
2615
+ self.update_lengths()
2616
+
2597
2617
  if is3D:
2598
2618
  length = self.length3D
2599
2619
  lengthparts = self._lengthparts3D
@@ -2601,15 +2621,6 @@ class vector:
2601
2621
  length = self.length2D
2602
2622
  lengthparts = self._lengthparts2D
2603
2623
 
2604
- if length is None:
2605
- self.update_lengths()
2606
- if is3D:
2607
- length = self.length3D
2608
- lengthparts = self._lengthparts3D
2609
- else:
2610
- length = self.length2D
2611
- lengthparts = self._lengthparts2D
2612
-
2613
2624
  cums = np.cumsum(lengthparts)
2614
2625
 
2615
2626
  if adim:
@@ -2628,7 +2639,7 @@ class vector:
2628
2639
 
2629
2640
  if frombegin:
2630
2641
  k=0
2631
- while s>cums[k]:
2642
+ while s>cums[k] and k < self.nbvertices-2:
2632
2643
  k+=1
2633
2644
  else:
2634
2645
  k=self.nbvertices-2
@@ -4868,19 +4879,23 @@ class zone:
4868
4879
  veccenter = self.myvectors[0]
4869
4880
  veccenter.update_lengths()
4870
4881
 
4882
+ logging.info(_('Length of the center vector: {}').format(veccenter.length2D))
4883
+
4871
4884
  # Returned zone
4872
4885
  myparallels = zone()
4873
4886
 
4874
4887
  if interval_parallel is None :
4888
+ logging.warning(_('Interval between parallels is not defined --> set to farthest_parallel'))
4875
4889
  interval_parallel : farthest_parallel
4876
4890
 
4877
4891
  if interval_parallel > farthest_parallel:
4878
- logging.warning(_('dspar is greater than dpar --> dspar is set to dpar'))
4892
+ logging.warning(_('Interval between parallels is greater than farthest_parallel --> set to farthest_parallel'))
4879
4893
  interval_parallel = farthest_parallel
4880
4894
 
4881
4895
  # All parallel distances
4882
4896
  all_par = np.arange(0, farthest_parallel, interval_parallel)[1:]
4883
4897
  all_par = np.concatenate((all_par,[farthest_parallel]))
4898
+ logging.info(_('All parallel distances: {}').format(all_par))
4884
4899
 
4885
4900
  for curpar in tqdm(all_par):
4886
4901
  # add current parallel to the dicts
@@ -4895,22 +4910,28 @@ class zone:
4895
4910
  #
4896
4911
  # gestion de vecteurs d'intersection
4897
4912
  for curint in intersect.myvectors:
4913
+ if not curint.used:
4914
+ continue
4915
+
4898
4916
  # bouclage sur les vecteurs
4899
- curint2 = curint.parallel_offset(eps_offset, side='right')
4917
+ curint1 = curint.parallel_offset(-eps_offset/2., side='left')
4918
+ curint2 = curint.parallel_offset( eps_offset/2., side='right')
4900
4919
 
4901
4920
  # recherche si une intersection existe
4902
- pt, dist = vecleft[curpar].intersection(curint, eval_dist=True, force_single=True)
4921
+ pt, dist = vecleft[curpar].intersection(curint1, eval_dist=True, force_single=True)
4903
4922
  if pt is not None:
4923
+ logging.debug(_('Intersection found on left parallel at distance {}').format(dist))
4904
4924
  #Une intersection existe --> on ajoute la portion de vecteur
4905
4925
 
4906
4926
  # Projection du point d'intersection sur le vecteur à suivre
4907
- curls = curint.asshapely_ls()
4908
- dist2 = curls.project(pt)
4927
+ dist2 = curint1.linestring.project(pt)
4928
+
4909
4929
  # recherche de la portion de vecteur
4910
4930
  # subs = extrêmité -> intersection
4911
4931
  # subs_inv = intersection -> extrêmité
4912
- subs = curint.substring(0. , dist2, is3D=False, adim=False)
4932
+ subs = curint1.substring(0. , dist2, is3D=False, adim=False)
4913
4933
  subs.reverse()
4934
+
4914
4935
  subs2 = curint2.substring(0., dist2, is3D=False, adim=False)
4915
4936
 
4916
4937
  vec1 = vecleft[curpar].substring(0., dist, is3D=False, adim=False)
@@ -4925,13 +4946,19 @@ class zone:
4925
4946
  # mise à jour des caractéristiques
4926
4947
  vecleft[curpar].find_minmax()
4927
4948
  vecleft[curpar].update_lengths()
4949
+ vecleft[curpar].reset_linestring()
4950
+ curint1.reset_linestring()
4951
+ curint2.reset_linestring()
4928
4952
 
4929
- pt, dist = vecright[curpar].intersection(curint, eval_dist=True, force_single=True)
4953
+ pt, dist = vecright[curpar].intersection(curint1, eval_dist=True, force_single=True)
4930
4954
  if pt is not None:
4931
- curls = curint.asshapely_ls()
4932
- dist2 = curls.project(pt)
4955
+ logging.debug(_('Intersection found on right parallel at distance {}').format(dist))
4956
+
4957
+ dist2 = curint1.linestring.project(pt)
4958
+
4933
4959
  #Une intersection existe --> on ajoute la portion de vecteur
4934
- subs = curint.substring(0., dist2, is3D=False, adim=False)
4960
+ subs = curint1.substring(0., dist2, is3D=False, adim=False)
4961
+
4935
4962
  subs2 = curint2.substring(0., dist2, is3D=False, adim=False)
4936
4963
  subs2.reverse()
4937
4964
 
@@ -4940,8 +4967,11 @@ class zone:
4940
4967
 
4941
4968
  vecright[curpar].myvertices = vec1.myvertices.copy() + subs2.myvertices.copy() + subs.myvertices.copy() + vec2.myvertices.copy()
4942
4969
 
4943
- vecright[curpar].update_lengths()
4944
4970
  vecright[curpar].find_minmax()
4971
+ vecright[curpar].update_lengths()
4972
+ vecright[curpar].reset_linestring()
4973
+ curint1.reset_linestring()
4974
+ curint2.reset_linestring()
4945
4975
 
4946
4976
  #Shapely LineString
4947
4977
  lsl:dict[str,LineString] = {key:vec.asshapely_ls() for key,vec in vecleft.items()}
@@ -4960,7 +4990,7 @@ class zone:
4960
4990
  ptsc = [veccenter.interpolate(curs, is3D=False, adim=False) for curs in sloc]
4961
4991
  ptsc2 = [veccenter.interpolate(curs, is3D=False, adim=False) for curs in sloc2]
4962
4992
 
4963
- sc = [lsc.project(Point(curs.x, curs.y)) for curs in ptsc]
4993
+ sc = [lsc.project(Point(curs.x, curs.y)) for curs in ptsc]
4964
4994
  sc2 = [lsc.project(Point(curs.x, curs.y)) for curs in ptsc2]
4965
4995
 
4966
4996
  #Real distances along left, right and center vector
@@ -5001,9 +5031,9 @@ class zone:
5001
5031
 
5002
5032
  if howmanypoly==1:
5003
5033
  #un seul polygone sur base des // gauche et droite
5004
- zonepoly = zone(name='polygons_'+self.myname,parent=self.parent)
5034
+ zonepoly = zone(name='polygons_'+self.myname, parent=self.parent)
5005
5035
 
5006
- self.parent.add_zone(zonepoly)
5036
+ self.parent.add_zone(zonepoly, forceparent=True)
5007
5037
 
5008
5038
  for i in range(nb):
5009
5039
  ptc1 = sc[i]
@@ -5037,16 +5067,16 @@ class zone:
5037
5067
  #force to close the polygon
5038
5068
  curvec.close_force()
5039
5069
  #add vector to zone
5040
- zonepoly.add_vector(curvec)
5070
+ zonepoly.add_vector(curvec, forceparent=True)
5041
5071
 
5042
5072
  #force to update minmax in the zone --> mandatory to plot
5043
5073
  zonepoly.find_minmax(True)
5044
5074
  else:
5045
5075
  #deux polygones sur base des // gauche et droite
5046
- zonepolyleft = zone(name='polygons_left_'+self.myname,parent=self.parent)
5047
- zonepolyright = zone(name='polygons_right_'+self.myname,parent=self.parent)
5048
- self.parent.add_zone(zonepolyleft)
5049
- self.parent.add_zone(zonepolyright)
5076
+ zonepolyleft = zone(name='polygons_left_'+self.myname, parent=self.parent)
5077
+ zonepolyright = zone(name='polygons_right_'+self.myname, parent=self.parent)
5078
+ self.parent.add_zone(zonepolyleft, forceparent=True)
5079
+ self.parent.add_zone(zonepolyright, forceparent=True)
5050
5080
 
5051
5081
  for i in range(nb):
5052
5082
  ptc1 = sc[i]
@@ -5058,8 +5088,8 @@ class zone:
5058
5088
 
5059
5089
  #mean distance along center will be stored as Z value of each vertex
5060
5090
  smean =(ptc1+ptc2)/2.
5061
- curvecleft=vector(name='poly'+str(i+1),parentzone=zonepolyleft)
5062
- curvecright=vector(name='poly'+str(i+1),parentzone=zonepolyright)
5091
+ curvecleft=vector(name='poly'+str(i+1), parentzone=zonepolyleft)
5092
+ curvecright=vector(name='poly'+str(i+1), parentzone=zonepolyright)
5063
5093
 
5064
5094
  #Substring for Left and Right
5065
5095
  sublsl=vecleft[farthest_parallel].substring(pt1[-1], pt2[-1], is3D=False, adim=False)
@@ -5077,8 +5107,8 @@ class zone:
5077
5107
  downl.reverse()
5078
5108
  downr = [wolfvertex(pt[i].x, pt[i].y) for pt in ptr2.values()]
5079
5109
 
5080
- curvecleft.myvertices = sublsl.myvertices.copy() + downl[1:-1].copy() + [sublscr.myvertices.copy()] + upl[1:-1].copy()
5081
- curvecright.myvertices = sublsc.myvertices.copy() + downr[1:-1].copy() + [sublsr.myvertices.copy()] + upr[1:-1].copy()
5110
+ curvecleft.myvertices = sublsl.myvertices.copy() + downl[1:-1].copy() + sublscr.myvertices.copy() + upl[1:-1].copy()
5111
+ curvecright.myvertices = sublsc.myvertices.copy() + downr[1:-1].copy() + sublsr.myvertices.copy() + upr[1:-1].copy()
5082
5112
 
5083
5113
  for curvert in curvecleft.myvertices:
5084
5114
  curvert.z = smean
@@ -5096,6 +5126,9 @@ class zone:
5096
5126
 
5097
5127
  self._fill_structure()
5098
5128
 
5129
+ if self.get_mapviewer() is not None:
5130
+ self.get_mapviewer().Paint()
5131
+
5099
5132
  return myparallels
5100
5133
 
5101
5134
  def get_values_linked_polygons(self, linked_arrays, stats=True) -> dict:
@@ -5903,6 +5936,15 @@ class Zones(wx.Frame, Element_To_Draw):
5903
5936
  if self.filename!='':
5904
5937
  # lecture du fichier
5905
5938
 
5939
+ # Check if fname is an url
5940
+ _filename = str(self.filename).strip()
5941
+ if _filename.startswith('http:') or _filename.startswith('https:'):
5942
+ try:
5943
+ self.filename = str(download_file(_filename))
5944
+ except Exception as e:
5945
+ logging.error(_('Error while downloading file: %s') % e)
5946
+ return
5947
+
5906
5948
  if self.filename.endswith('.dxf'):
5907
5949
  self.is2D=False
5908
5950
  self.import_dxf(self.filename)
@@ -7804,6 +7846,7 @@ class Zones(wx.Frame, Element_To_Draw):
7804
7846
  """
7805
7847
 
7806
7848
  if self.active_zone is None:
7849
+ logging.warning(_('No active zone - Nothing to do !'))
7807
7850
  return
7808
7851
 
7809
7852
  if self.wx_exists:
@@ -7813,25 +7856,81 @@ class Zones(wx.Frame, Element_To_Draw):
7813
7856
  logging.warning(_('The active zone must contain 3 vectors and only 3'))
7814
7857
  return
7815
7858
 
7816
- dlg=wx.NumberEntryDialog(None,_('What is the desired longitudinal size [cm] ?'),'ds','ds size',500,1,10000)
7817
- ret=dlg.ShowModal()
7818
- if ret==wx.ID_CANCEL:
7819
- dlg.Destroy()
7820
- return
7859
+ self.active_zone.myvectors[1].update_lengths()
7821
7860
 
7822
- ds=float(dlg.GetValue())/100.
7823
- dlg.Destroy()
7861
+ poly_dlg = wx.Dialog(None, title=_('Polygons from parallels options'), size=(400, 350))
7862
+ poly_dlg.SetBackgroundColour(wx.Colour(240, 240, 240))
7863
+ poly_sizer = wx.BoxSizer(wx.VERTICAL)
7864
+ poly_sizer.Add(wx.StaticText(poly_dlg, label=_('Polygons from parallels options')), 0, wx.ALL | wx.CENTER, 5)
7865
+ poly_sizer.Add(wx.StaticText(poly_dlg, label=_('This will create polygons from the parallels in the active zone')), 0, wx.ALL | wx.CENTER, 5)
7866
+ poly_sizer.Add(wx.StaticText(poly_dlg, label=_('Please enter the parameters below:')), 0, wx.ALL | wx.CENTER, 5)
7867
+ poly_sizer.Add(wx.StaticText(poly_dlg, label=_('Longitudinal size [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7868
+ ds_text = wx.TextCtrl(poly_dlg, value='5000') # Default
7869
+ poly_sizer.Add(ds_text, 0, wx.ALL | wx.EXPAND, 5)
7870
+ poly_sizer.Add(wx.StaticText(poly_dlg, label=_('How many polygons? \n\n 1 = one large polygon from left to right\n 2 = two polygons - one left and one right')), 0, wx.ALL | wx.LEFT, 5)
7871
+ nb_text = wx.TextCtrl(poly_dlg, value='1') # Default
7872
+ poly_sizer.Add(nb_text, 0, wx.ALL | wx.EXPAND, 5)
7873
+ ok_button = wx.Button(poly_dlg, label=_('OK'))
7874
+ ok_button.Bind(wx.EVT_BUTTON, lambda evt: self._OnCreatePolygons(evt, ds_text, nb_text, poly_dlg))
7875
+ poly_sizer.Add(ok_button, 0, wx.ALL | wx.CENTER, 5)
7876
+ poly_dlg.SetSizer(poly_sizer)
7877
+ poly_dlg.Layout()
7878
+ poly_dlg.CentreOnParent()
7879
+ poly_dlg.ShowModal()
7824
7880
 
7825
- dlg=wx.NumberEntryDialog(None,_('How many polygons ? \n\n 1 = one large polygon from left to right\n 2 = two polygons - one left and one right'),'Number','Polygons',1,1,2)
7826
- ret=dlg.ShowModal()
7827
- if ret==wx.ID_CANCEL:
7828
- dlg.Destroy()
7881
+ # dlg=wx.NumberEntryDialog(None,_('What is the desired longitudinal size [cm] ?'),'ds','ds size',500,1,10000)
7882
+ # ret=dlg.ShowModal()
7883
+ # if ret==wx.ID_CANCEL:
7884
+ # dlg.Destroy()
7885
+ # return
7886
+
7887
+ # ds=float(dlg.GetValue())/100.
7888
+ # dlg.Destroy()
7889
+
7890
+ # dlg=wx.NumberEntryDialog(None,_('How many polygons ? \n\n 1 = one large polygon from left to right\n 2 = two polygons - one left and one right'),'Number','Polygons',1,1,2)
7891
+ # ret=dlg.ShowModal()
7892
+ # if ret==wx.ID_CANCEL:
7893
+ # dlg.Destroy()
7894
+ # return
7895
+
7896
+ # nb=int(dlg.GetValue())
7897
+ # dlg.Destroy()
7898
+
7899
+
7900
+ def _OnCreatePolygons(self, event:wx.MouseEvent, ds_text:wx.TextCtrl, nb_text:wx.TextCtrl, option_dialog:wx.Dialog):
7901
+ """
7902
+ Handle the creation of polygons based on user input from the dialog.
7903
+ """
7904
+
7905
+ try:
7906
+ ds = float(ds_text.GetValue()) / 100.0 # Convert cm to
7907
+ nb = int(nb_text.GetValue()) # Number of polygons
7908
+
7909
+ if ds <= 0:
7910
+ wx.MessageBox(_('Please enter a valid distance greater than 0.'), _('Input Error'), wx.OK | wx.ICON_ERROR)
7829
7911
  return
7830
7912
 
7831
- nb=int(dlg.GetValue())
7832
- dlg.Destroy()
7913
+ if ds > self.active_zone.myvectors[1].length2D:
7914
+ wx.MessageBox(_('The distance must be less than the length of the center vector in the active zone.'), _('Input Error'), wx.OK | wx.ICON_ERROR)
7915
+ return
7916
+
7917
+ if nb < 1 or nb > 2:
7918
+ wx.MessageBox(_('Please enter a valid number of polygons (1 or 2).'), _('Input Error'), wx.OK | wx.ICON_ERROR)
7919
+ return
7920
+ except ValueError:
7921
+ wx.MessageBox(_('Please enter valid numeric values for all fields.'), _('Input Error'), wx.OK | wx.ICON_ERROR)
7922
+ return
7833
7923
 
7924
+ try:
7834
7925
  self.active_zone.create_polygon_from_parallel(ds,nb)
7926
+ except Exception as e:
7927
+ logging.error(_('Error during polygon creation: {}').format(str(e)))
7928
+
7929
+ if self.get_mapviewer() is not None:
7930
+ self.get_mapviewer().Paint()
7931
+
7932
+ option_dialog.Destroy()
7933
+
7835
7934
 
7836
7935
  def Oncreateslidingpoly(self, event:wx.MouseEvent):
7837
7936
  """
@@ -7849,71 +7948,145 @@ class Zones(wx.Frame, Element_To_Draw):
7849
7948
  dlg.Destroy()
7850
7949
  return
7851
7950
 
7852
- #dialog box for length, sliding length, farthest parallel and parallel interval
7853
- dlg=wx.NumberEntryDialog(None,_('What is the desired longitudinal size [cm] ?'),'ds','ds size',5000,1,100000)
7854
- ret=dlg.ShowModal()
7855
- if ret==wx.ID_CANCEL:
7856
- dlg.Destroy()
7857
- return
7951
+ option_dialog = wx.Dialog(None, title=_('Sliding polygons options'), size=(450, 520))
7952
+ option_dialog.SetBackgroundColour(wx.Colour(240, 240, 240))
7953
+ option_sizer = wx.BoxSizer(wx.VERTICAL)
7954
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Sliding polygons options')), 0, wx.ALL | wx.CENTER, 5)
7955
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('This will create sliding polygons from the active vector in the active zone')), 0, wx.ALL | wx.CENTER, 5)
7956
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Please enter the parameters below:')), 0, wx.ALL | wx.CENTER, 5)
7957
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Longitudinal size [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7958
+ ds_text = wx.TextCtrl(option_dialog, value='5000') # Default value in cm
7959
+ option_sizer.Add(ds_text, 0, wx.ALL | wx.EXPAND, 5)
7960
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Sliding length [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7961
+ sliding_text = wx.TextCtrl(option_dialog, value='5000') # Default value
7962
+ option_sizer.Add(sliding_text, 0, wx.ALL | wx.EXPAND, 5)
7963
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Farthest parallel [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7964
+ farthest_text = wx.TextCtrl(option_dialog, value='10000') # Default
7965
+ option_sizer.Add(farthest_text, 0, wx.ALL | wx.EXPAND, 5)
7966
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('Parallel interval [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7967
+ interval_text = wx.TextCtrl(option_dialog, value='1000') # Default
7968
+ option_sizer.Add(interval_text, 0, wx.ALL | wx.EXPAND, 5)
7969
+
7970
+ intersect_sizer = wx.BoxSizer(wx.HORIZONTAL)
7971
+ inter_checkbox = wx.CheckBox(option_dialog, label=_('Use intersect zone if available'))
7972
+ inter_checkbox.SetValue(True) # Default to True
7973
+ offset_text = wx.TextCtrl(option_dialog, value='10') # Default offset value
7974
+ intersect_sizer.Add(inter_checkbox, 0, wx.ALL | wx.LEFT, 5)
7975
+ intersect_sizer.Add(wx.StaticText(option_dialog, label=_('Offset [cm]:')), 0, wx.ALL | wx.LEFT, 5)
7976
+ intersect_sizer.Add(offset_text, 0, wx.ALL | wx.EXPAND, 5)
7977
+ option_sizer.Add(wx.StaticText(option_dialog, label=_('If you have a zone named "intersect", you can use it to constrain the polygons.\nWhen constraint vectors are present, they cannot intersect the central vector.\nLikewise, they must be drawn moving away from the central vector.')), 0, wx.ALL | wx.CENTER, 5)
7978
+
7979
+ option_sizer.Add(intersect_sizer, 0, wx.ALL | wx.LEFT, 5)
7980
+ separate_checkbox = wx.CheckBox(option_dialog, label=_('Separate left and right polygons'))
7981
+ separate_checkbox.SetValue(False) # Default to False
7982
+ option_sizer.Add(separate_checkbox, 0, wx.ALL | wx.LEFT, 5)
7983
+ ok_button = wx.Button(option_dialog, label=_('OK'))
7984
+ ok_button.Bind(wx.EVT_BUTTON, lambda evt: self._OnCreateSlidingPolygon(evt, ds_text, sliding_text, farthest_text, interval_text, inter_checkbox, offset_text, separate_checkbox, option_dialog))
7985
+ option_sizer.Add(ok_button, 0, wx.ALL | wx.CENTER, 5)
7986
+ option_dialog.SetSizer(option_sizer)
7987
+ option_dialog.Layout()
7988
+ option_dialog.Centre()
7858
7989
 
7859
- ds=float(dlg.GetValue())/100.
7990
+ try:
7991
+ option_dialog.ShowModal()
7992
+ except:
7993
+ logging.error(_('Error during sliding polygons calculation.'))
7860
7994
 
7861
- dlg.Destroy()
7995
+ option_dialog.Destroy()
7862
7996
 
7863
- dlg=wx.NumberEntryDialog(None,_('What is the desired sliding length [cm] ?'),'sliding','sliding size',5000,1,100000)
7864
- ret=dlg.ShowModal()
7865
- if ret==wx.ID_CANCEL:
7866
- dlg.Destroy()
7997
+ def _OnCreateSlidingPolygon(self, event, ds_text, sliding_text, farthest_text, interval_text, inter_checkbox, offset_text, separate_checkbox, option_dialog:wx.Dialog):
7998
+ """
7999
+ Handle the creation of sliding polygons based on user input from the dialog.
8000
+ """
8001
+
8002
+ try:
8003
+ ds = float(ds_text.GetValue()) / 100.0 # Convert cm to m
8004
+ sliding = float(sliding_text.GetValue()) / 100.0 # Convert cm
8005
+ farthest = float(farthest_text.GetValue()) / 100.0 # Convert cm to m
8006
+ interval = float(interval_text.GetValue()) / 100.0 # Convert cm to
8007
+ intersect = inter_checkbox.GetValue() # Boolean value
8008
+ separate = separate_checkbox.GetValue() # Boolean value
8009
+ offset = float(offset_text.GetValue())/100.0 # Offset value in m
8010
+ except ValueError:
8011
+ wx.MessageBox(_('Please enter valid numeric values for all fields.'), _('Input Error'), wx.OK | wx.ICON_ERROR)
7867
8012
  return
7868
8013
 
7869
- sliding=float(dlg.GetValue())/100.
8014
+ if separate:
8015
+ howmany = 2 # Separate left and right polygons
8016
+ else:
8017
+ howmany = 1 # Single polygon
7870
8018
 
7871
- dlg.Destroy()
8019
+ # #dialog box for length, sliding length, farthest parallel and parallel interval
8020
+ # dlg=wx.NumberEntryDialog(None,_('What is the desired longitudinal size [cm] ?'),'ds','ds size',5000,1,100000)
8021
+ # ret=dlg.ShowModal()
8022
+ # if ret==wx.ID_CANCEL:
8023
+ # dlg.Destroy()
8024
+ # return
7872
8025
 
7873
- dlg=wx.NumberEntryDialog(None,_('What is the desired farthest parallel [cm] ?'),'farthest','farthest size',10000,1,100000)
7874
- ret=dlg.ShowModal()
7875
- if ret==wx.ID_CANCEL:
7876
- dlg.Destroy()
7877
- return
8026
+ # ds=float(dlg.GetValue())/100.
7878
8027
 
7879
- farthest=float(dlg.GetValue())/100.
8028
+ # dlg.Destroy()
7880
8029
 
7881
- dlg.Destroy()
8030
+ # dlg=wx.NumberEntryDialog(None,_('What is the desired sliding length [cm] ?'),'sliding','sliding size',5000,1,100000)
8031
+ # ret=dlg.ShowModal()
8032
+ # if ret==wx.ID_CANCEL:
8033
+ # dlg.Destroy()
8034
+ # return
7882
8035
 
7883
- dlg=wx.NumberEntryDialog(None,_('What is the desired parallel interval [cm] ?'),'interval','interval size',int(farthest*10.),1,int(farthest*100.))
7884
- ret=dlg.ShowModal()
7885
- if ret==wx.ID_CANCEL:
7886
- dlg.Destroy()
7887
- return
8036
+ # sliding=float(dlg.GetValue())/100.
7888
8037
 
7889
- interval=float(dlg.GetValue())/100.
8038
+ # dlg.Destroy()
7890
8039
 
7891
- dlg.Destroy()
8040
+ # dlg=wx.NumberEntryDialog(None,_('What is the desired farthest parallel [cm] ?'),'farthest','farthest size',10000,1,100000)
8041
+ # ret=dlg.ShowModal()
8042
+ # if ret==wx.ID_CANCEL:
8043
+ # dlg.Destroy()
8044
+ # return
7892
8045
 
7893
- zones_names=[curz.myname for curz in self.myzones]
7894
- if "intersect" in zones_names:
7895
- dlg = wx.MessageDialog(None,_('Do you want to use the intersect zone ?'),style=wx.YES_NO)
7896
- ret=dlg.ShowModal()
7897
- if ret==wx.ID_YES:
7898
- inter = True
7899
- else:
7900
- inter = False
7901
- dlg.Destroy()
7902
- else:
7903
- inter = False
8046
+ # farthest=float(dlg.GetValue())/100.
8047
+
8048
+ # dlg.Destroy()
8049
+
8050
+ # dlg=wx.NumberEntryDialog(None,_('What is the desired parallel interval [cm] ?'),'interval','interval size',int(farthest*10.),1,int(farthest*100.))
8051
+ # ret=dlg.ShowModal()
8052
+ # if ret==wx.ID_CANCEL:
8053
+ # dlg.Destroy()
8054
+ # return
8055
+
8056
+ # interval=float(dlg.GetValue())/100.
8057
+
8058
+ # dlg.Destroy()
8059
+
8060
+ zones_names=[curz.myname.lower() for curz in self.myzones]
8061
+ # if "intersect" in zones_names:
8062
+ # dlg = wx.MessageDialog(None,_('Do you want to use the intersect zone ?'),style=wx.YES_NO)
8063
+ # ret=dlg.ShowModal()
8064
+ # if ret==wx.ID_YES:
8065
+ # inter = True
8066
+ # else:
8067
+ # inter = False
8068
+ # dlg.Destroy()
8069
+ # else:
8070
+ # inter = False
7904
8071
 
7905
8072
  inter_zone = None
7906
- if inter:
7907
- inter_zone = self.myzones[zones_names.index("intersect")]
8073
+ if intersect:
8074
+ if "intersect" in zones_names:
8075
+ inter_zone = self.myzones[zones_names.index("intersect")]
8076
+
8077
+ # dlg = wx.MessageDialog(None,_('Do you want to separate left and right polygons ?'),style=wx.YES_NO)
8078
+ # ret=dlg.ShowModal()
8079
+ # if ret==wx.ID_YES:
8080
+ # howmany = 2
8081
+ # else:
8082
+ # howmany = 1
7908
8083
 
7909
- dlg = wx.MessageDialog(None,_('Do you want to separate left and right polygons ?'),style=wx.YES_NO)
7910
- ret=dlg.ShowModal()
7911
- if ret==wx.ID_YES:
7912
- howmany = 2
7913
- else:
7914
- howmany = 1
8084
+ try:
8085
+ self.active_zone.create_sliding_polygon_from_parallel(ds, sliding, farthest, interval, inter_zone, howmany, eps_offset=offset)
8086
+ except:
8087
+ logging.error(_('Error during sliding polygons calculation.'))
7915
8088
 
7916
- self.active_zone.create_sliding_polygon_from_parallel(ds, sliding, farthest, interval, inter_zone, howmany)
8089
+ option_dialog.Close()
7917
8090
 
7918
8091
 
7919
8092
  def Oncreatebin(self,event:wx.MouseEvent):
@@ -8605,9 +8778,15 @@ class Zones(wx.Frame, Element_To_Draw):
8605
8778
 
8606
8779
  self.active_zone.reset_listogl()
8607
8780
  self.myzones.pop(int(self.myzones.index(self.active_zone)))
8781
+ self.Activate_vector(None)
8782
+ self.Activate_zone(None)
8783
+
8608
8784
  self.fill_structure()
8609
8785
  self.find_minmax(True)
8610
8786
 
8787
+ if self.get_mapviewer() is not None:
8788
+ self.get_mapviewer().Paint()
8789
+
8611
8790
  def OnClickfindactivate_vector(self, event:wx.MouseEvent):
8612
8791
  """
8613
8792
  Recherche et activation d'un vecteur dans toutes les zones
@@ -8714,11 +8893,7 @@ class Zones(wx.Frame, Element_To_Draw):
8714
8893
  return
8715
8894
 
8716
8895
  curname=self.active_vector.myname
8717
- r = wx.MessageDialog(
8718
- None,
8719
- _('The vector {n} will be deleted. Continue?').format(n=curname),
8720
- style=wx.YES_NO | wx.ICON_QUESTION
8721
- ).ShowModal()
8896
+ r = wx.MessageDialog(None, _('The vector {n} will be deleted. Continue?').format(n=curname), style=wx.YES_NO | wx.ICON_QUESTION).ShowModal()
8722
8897
 
8723
8898
  if r != wx.ID_YES:
8724
8899
  return
@@ -8730,14 +8905,23 @@ class Zones(wx.Frame, Element_To_Draw):
8730
8905
 
8731
8906
  idx = int(actzone.myvectors.index(self.active_vector))
8732
8907
  if idx >= 0 and idx < actzone.nbvectors:
8908
+ actzone.reset_listogl()
8733
8909
  actzone.myvectors.pop(idx)
8734
8910
 
8735
- if actzone.nbvectors==0:
8911
+ if actzone.nbvectors == 0:
8736
8912
  self.Activate_vector(None)
8913
+ elif idx < actzone.nbvectors:
8914
+ self.Activate_vector(actzone.myvectors[idx])
8915
+ else:
8916
+ self.Activate_vector(actzone.myvectors[-1])
8737
8917
 
8738
8918
  self.fill_structure()
8739
8919
  self.find_minmax(True)
8740
8920
 
8921
+ if self.get_mapviewer() is not None:
8922
+ self.get_mapviewer().Paint()
8923
+
8924
+
8741
8925
  def OnClickup_vector(self, event:wx.MouseEvent):
8742
8926
  """Remonte le vecteur actif dans la liste de la zone"""
8743
8927
  if self.verify_activevec():