@@ -64,7 +64,6 @@ def update(self, parent, iniFile):
6464
6565		# test for axis letter(s) changed 
6666		if  len (tool_joints ) ==  len (ini_joints ): # this has problems if many axes are changed 
67- 			#print('Same number of joints, checking Axis Letters') 
6867			for  key , value  in  tool_joints .items ():
6968				if  tool_joints [key ] !=  ini_joints [key ]:
7069					new_axis  =  f'[AXIS_{ tool_joints [key ]}  ]' 
@@ -74,7 +73,6 @@ def update(self, parent, iniFile):
7473						if  line .strip () ==  f'[AXIS_{ ini_joints [key ]}  ]' :
7574							for  index , line  in  enumerate (self .content ):
7675								if  line .strip () ==  old_axis :
77- 									#print(f'Index: {index} Old: {old_axis} New: {new_axis}') 
7876									self .content [index ] =  f'{ new_axis } \n ' 
7977									self .get_sections ()
8078									for  line  in  self .content :
@@ -89,7 +87,6 @@ def update(self, parent, iniFile):
8987					del  self .content [start :end ]
9088					self .get_sections ()
9189					if  value  not  in   tool_joints .values ():
92- 						#print(f'Remvoing [AXIS_{value}]') 
9390						axis  =  f'[AXIS_{ value }  ]' 
9491						start  =  self .sections [axis ][0 ]
9592						end  =  self .sections [axis ][1 ] +  1 
@@ -104,15 +101,12 @@ def update(self, parent, iniFile):
104101		elif  len (tool_joints ) >  len (ini_joints ):
105102			for  key , value  in  tool_joints .items ():
106103				if  key  not  in   ini_joints :
107- 					#print(f'Adding {key} after {last_key}') 
108104					last_end  =  self .sections [last_key ][1 ] +  1 
109- 					#print(f'Insert {key} at {last_end}') 
110105					self .content .insert (last_end , f'{ key } \n ' )
111106					self .content .insert (last_end  +  1 , '\n ' )
112107					self .get_sections ()
113108					# need to check to see if the axis has been create 
114109					if  f'[AXIS_{ value }  ]'  not  in   self .sections :
115- 						#print(f'Adding [AXIS_{value}] after {last_axis}') 
116110						last_end  =  self .sections [last_key ][1 ] +  1 
117111						self .content .insert (last_end , f'[AXIS_{ value }  ]\n ' )
118112						self .content .insert (last_end  +  1 , '\n ' )
@@ -350,73 +344,6 @@ def update(self, parent, iniFile):
350344		# coordinatesLB contains all the axes XYYZ 
351345		# [AXIS_x] section 
352346
353- 		''' 
354- 		# build axis joint(s) dictionaries 
355- 		tool_ja = {} 
356- 		joint = 0 
357- 		for i in range(4): 
358- 			for j in range(6): 
359- 				if getattr(parent, f'c{i}_axis_{j}').currentData(): 
360- 					tool_ja[f'[JOINT_{joint}]'] = f'[AXIS_{getattr(parent, f"c{i}_axis_{j}").currentData()}]' 
361- 					joint += 1 
362- 		#for key, value in tool_ja.items(): 
363- 		#	print(f'key: {key} value: {value}') 
364- 
365- 		ini_ja = {} 
366- 		for key, value in self.sections.items(): 
367- 			if key.startswith('[JOINT'): 
368- 				for i in range(value[0], value[1]): 
369- 					if self.content[i].startswith('AXIS'): 
370- 						axis = self.content[i].strip() 
371- 						axis = axis.split() 
372- 						axis = f'[AXIS_{axis[-1]}]' 
373- 						ini_ja[key] = axis 
374- 
375- 		if len(tool_ja) == len(ini_ja): 
376- 			if tool_ja != ini_ja: 
377- 				for key in tool_ja.keys(): 
378- 					if tool_ja[key] != ini_ja[key]: 
379- 						index = self.content.index(f'{ini_ja[key]}\n ') 
380- 						if index: 
381- 							self.content[index] = f'{tool_ja[key]}\n ' 
382- 							self.get_sections() # update section start/end 
383- 
384- 		elif len(tool_ja) > len(ini_ja): 
385- 			for key in ini_ja.keys(): # check for axis letter changed 
386- 				if tool_ja[key] != ini_ja[key]: 
387- 					index = self.content.index(f'{ini_ja[key]}\n ') 
388- 					if index: 
389- 						self.content[index] = f'{tool_ja[key]}\n ' 
390- 						self.get_sections() # update section start/end 
391- 
392- 			ini_axes = [] 
393- 			for key, value in ini_ja.items(): # get a list of axes 
394- 				if value not in ini_axes: 
395- 					ini_axes.append(value) 
396- 
397- 			last_axis = '' 
398- 			last_joint = '' 
399- 			# this fails if more than one joint is added !!!!!!!!!!! 
400- 			for key, value in tool_ja.items(): # add missing axis 
401- 				if tool_ja[key] not in ini_axes: 
402- 					print(f'key: {key}') 
403- 					index = self.sections[last_joint][1] 
404- 					if index: 
405- 						self.insert_section(index, f'{tool_ja[key]}') 
406- 				last_joint = key 
407- 
408- 			for key, value in tool_ja.items(): # add missing joint after last axis 
409- 				if key not in ini_ja.keys(): 
410- 					index = self.sections[value][1] 
411- 					self.insert_section(index, f'{key}') 
412- 
413- 		elif len(tool_ja) < len(ini_ja): # joint removed 
414- 			for joint, axis in ini_ja.items(): 
415- 				if joint not in tool_ja: 
416- 					self.delete_section(joint) 
417- 					self.delete_section(axis) 
418- 		''' 
419- 
420347		# finally update the [AXIS_n] and [JOINT_n] sections 
421348		axes  =  []
422349		n  =  0  # joint number 
@@ -426,18 +353,15 @@ def update(self, parent, iniFile):
426353					axis  =  getattr (parent , f'c{ i }  _axis_{ j }  ' ).currentData ()
427354					if  axis  not  in   axes :
428355						axes .append (axis )
429- 						 #print(f'AXIS_{axis} MIN_LIMIT {getattr(parent, f"c{i}_min_limit_{j}").text()}') 
356+ 
430357						self .update_key (f'AXIS_{ axis }  ' , 'MIN_LIMIT' , getattr (parent , f'c{ i }  _min_limit_{ j }  ' ).text ())
431358						self .update_key (f'AXIS_{ axis }  ' , 'MAX_LIMIT' , getattr (parent , f'c{ i }  _max_limit_{ j }  ' ).text ())
432359						self .update_key (f'AXIS_{ axis }  ' , 'MAX_VELOCITY' , getattr (parent , f'c{ i }  _max_vel_{ j }  ' ).text ())
433360						self .update_key (f'AXIS_{ axis }  ' , 'MAX_ACCELERATION' , getattr (parent , f'c{ i }  _max_accel_{ j }  ' ).text ())
434- 					#iniContents.append(f'CARD = {i}\n') 
435- 					#iniContents.append(f'TAB = {j}\n') 
436361
437362					self .update_key (f'JOINT_{ n }  ' , 'CARD' , f'{ i }  ' )
438363					self .update_key (f'JOINT_{ n }  ' , 'TAB' , f'{ j }  ' )
439364					self .update_key (f'JOINT_{ n }  ' , 'AXIS' , getattr (parent , f'c{ i }  _axis_{ j }  ' ).currentData ())
440- 					#print(f'JOINT_{n} MIN_LIMIT {getattr(parent, f"c{i}_min_limit_{j}").text()}') 
441365					self .update_key (f'JOINT_{ n }  ' , 'MIN_LIMIT' , getattr (parent , f'c{ i }  _min_limit_{ j }  ' ).text ())
442366					self .update_key (f'JOINT_{ n }  ' , 'MAX_LIMIT' , getattr (parent , f'c{ i }  _max_limit_{ j }  ' ).text ())
443367					self .update_key (f'JOINT_{ n }  ' , 'MAX_VELOCITY' , getattr (parent , f'c{ i }  _max_vel_{ j }  ' ).text ())
@@ -730,19 +654,15 @@ def get_sections(self):
730654			previous  =  key 
731655
732656	def  update_key (self , section , key , value ):
733- 		#if key == 'HOME_IGNORE_LIMITS': 
734- 		#	print(section, key, value) 
735657		found  =  False 
736658		start  =  self .sections [f'[{ section }  ]' ][0 ]
737659		end  =  self .sections [f'[{ section }  ]' ][1 ]
738660		for  item  in  self .content [start :end ]:
739661			if  item .split ('=' )[0 ].strip () ==  key :
740- 				index  =  self .content .index (item )
662+ 				index  =  self .content .index (item ,  start )
741663				self .content [index ] =  f'{ key }   = { value } \n ' 
742664				found  =  True 
743665				break 
744- 			#else: 
745- 			#	found = False 
746666		if  not  found :
747667			self .content .insert (end , f'{ key }   = { value } \n ' )
748668			self .get_sections () # update section start/end 
0 commit comments