@@ -30,6 +30,9 @@ public partial class DevicePDOView2 : MyTabUserControl
3030
3131 Point RightClickPoint = new Point ( 0 , 0 ) ;
3232
33+ // Info columns: ID, COB, Index
34+ const int INFO_COLS_COUNT = 3 ;
35+
3336 public DevicePDOView2 ( )
3437 {
3538 InitializeComponent ( ) ;
@@ -54,15 +57,15 @@ public DevicePDOView2()
5457
5558 for ( int x = 0 ; x < 64 ; x ++ )
5659 {
57- grid1 [ 0 , 3 + x ] = new MyHeader ( string . Format ( "{0}" , x ) ) ;
60+ grid1 [ 0 , INFO_COLS_COUNT + x ] = new MyHeader ( string . Format ( "{0}" , x ) ) ;
5861 }
5962
6063 for ( int x = 0 ; x < 8 ; x ++ )
6164 {
62- grid1 [ 1 , 3 + x * 8 ] = new MyHeader ( string . Format ( "Byte {0}" , x ) ) ;
63- grid1 [ 1 , 3 + x * 8 ] . ColumnSpan = 8 ;
65+ grid1 [ 1 , INFO_COLS_COUNT + x * 8 ] = new MyHeader ( string . Format ( "Byte {0}" , x ) ) ;
66+ grid1 [ 1 , INFO_COLS_COUNT + x * 8 ] . ColumnSpan = 8 ;
6467
65- grid1 [ 1 , 3 + x * 8 ] . View . BackColor = Color . Tomato ;
68+ grid1 [ 1 , INFO_COLS_COUNT + x * 8 ] . View . BackColor = Color . Tomato ;
6669
6770 }
6871
@@ -85,6 +88,7 @@ private void ContextMenuStrip_removeitem_ItemClicked(object sender, ToolStripIte
8588 int foundrow , foundcol ;
8689 SourceGrid . Cells . ICellVirtual v = getItemAtGridPoint ( RightClickPoint , out foundrow , out foundcol ) ;
8790 SourceGrid . Cells . Cell c = ( SourceGrid . Cells . Cell ) v ;
91+ var width_limit = 64 + INFO_COLS_COUNT - foundcol ;
8892
8993 if ( c == null )
9094 return ;
@@ -98,15 +102,29 @@ private void ContextMenuStrip_removeitem_ItemClicked(object sender, ToolStripIte
98102 switch ( e . ClickedItem . Tag )
99103 {
100104 case "remove" :
101- location . slot . Mapping . Remove ( location . entry ) ;
105+ location . slot . Mapping . Remove ( location . mappingentry ) ;
102106
103107 break ;
104108
105109 case "insert" :
106- ODentry od = new ODentry ( ) ;
107- location . slot . Mapping . Insert ( location . ordinal , eds . dummy_ods [ 0x002 ] ) ;
110+ PDOMappingEntry od = new PDOMappingEntry ( ) ;
111+ od . entry = eds . dummy_ods [ 0x002 ] ;
112+ od . width = Math . Min ( od . entry . Sizeofdatatype ( ) , width_limit ) ;
113+ location . slot . Mapping . Insert ( location . ordinal , od ) ;
108114 break ;
109115
116+ case "changewidth" :
117+ var mapping = location . slot . Mapping [ location . ordinal ] ;
118+ width_limit = Math . Min ( mapping . entry . Sizeofdatatype ( ) , width_limit ) ;
119+ if ( mapping . width > width_limit )
120+ mapping . width = width_limit ;
121+ var temp = new ChangeMappingWidth ( mapping . width , width_limit ) ;
122+ if ( temp . ShowDialog ( ) == DialogResult . OK )
123+ {
124+ mapping . width = temp . selected_width ;
125+ location . slot . Mapping [ location . ordinal ] = mapping ;
126+ }
127+ break ;
110128 }
111129
112130 helper . buildmappingsfromlists ( ( ExporterFactory . Exporter ) Properties . Settings . Default . ExporterType == ExporterFactory . Exporter . CANOPENNODE_V4 ) ;
@@ -133,25 +151,39 @@ private void Vcc_ValueChangedEvent(object sender, EventArgs e)
133151 PDOlocator location = ( PDOlocator ) ( ( SourceGrid . Cells . Cell ) cell . Cell ) . Tag ;
134152 PDOSlot slot = location . slot ;
135153
136- ODentry newentry = null ;
154+ var newmapping = new PDOMappingEntry ( ) ;
137155
138- if ( eds . tryGetODEntry ( newindex , out newentry ) )
156+ if ( eds . tryGetODEntry ( newindex , out newmapping . entry ) )
139157 {
140158 if ( newsubindex != 0 )
141- newentry = newentry . subobjects [ newsubindex ] ;
159+ {
160+ newmapping . entry = newmapping . entry . subobjects [ newsubindex ] ;
161+ newmapping . width = newmapping . entry . Sizeofdatatype ( ) ;
162+ }
142163 }
143164 else
144165 {
145166 return ;
146167 }
147168
148- if ( location . entry == null )
169+ int current_width = newmapping . entry . Sizeofdatatype ( ) ;
170+ int width_limit = 64 + INFO_COLS_COUNT - cell . Position . Column ;
171+ width_limit = Math . Min ( width_limit , newmapping . entry . Sizeofdatatype ( ) ) ;
172+ current_width = Math . Min ( width_limit , current_width ) ;
173+ newmapping . width = current_width ;
174+ var change_pdo_entry_width = new ChangeMappingWidth ( current_width , width_limit ) ;
175+ if ( change_pdo_entry_width . ShowDialog ( ) == DialogResult . OK )
149176 {
150- slot . Mapping . Add ( newentry ) ;
177+ newmapping . width = change_pdo_entry_width . selected_width ;
178+ }
179+
180+ if ( location . mappingentry . entry == null )
181+ {
182+ slot . Mapping . Add ( newmapping ) ;
151183 }
152184 else
153185 {
154- slot . Mapping [ location . ordinal ] = newentry ;
186+ slot . Mapping [ location . ordinal ] = newmapping ;
155187 }
156188
157189 helper . buildmappingsfromlists ( ( ExporterFactory . Exporter ) Properties . Settings . Default . ExporterType == ExporterFactory . Exporter . CANOPENNODE_V4 ) ;
@@ -427,7 +459,6 @@ public void UpdatePDOinfo(bool updatechoices = true)
427459 #if ! NETCOREAPP
428460 comboStandard . Control . DropDownWidth = 0x100 ;
429461 #endif
430- comboStandard . Changed += ComboStandard_Changed ;
431462
432463 //tableLayoutPanel1.SuspendLayout();
433464
@@ -444,8 +475,8 @@ public void UpdatePDOinfo(bool updatechoices = true)
444475 {
445476 if ( isTXPDO != slot . isTXPDO ( ) )
446477 continue ;
447- if ( grid1 . ColumnsCount > 64 + 3 )
448- grid1 . ColumnsCount = 64 + 3 ;
478+ if ( grid1 . ColumnsCount > 64 + INFO_COLS_COUNT )
479+ grid1 . ColumnsCount = 64 + INFO_COLS_COUNT ;
449480 grid1 . Redim ( grid1 . RowsCount + 1 , grid1 . ColumnsCount ) ;
450481 grid1 . Rows [ grid1 . RowsCount - 1 ] . Tag = slot ;
451482 grid1 . Rows [ row + 2 ] . Height = 30 ;
@@ -460,33 +491,34 @@ public void UpdatePDOinfo(bool updatechoices = true)
460491
461492 int bitoff = 0 ;
462493 int ordinal = 0 ;
463- foreach ( ODentry entry in slot . Mapping )
494+ foreach ( PDOMappingEntry mappingentry in slot . Mapping )
464495 {
465- if ( ( bitoff + entry . Sizeofdatatype ( ) ) > 64 )
496+ if ( ( bitoff + mappingentry . width ) > 64 )
466497 {
467498 string toDisplay = string . Join ( Environment . NewLine , slot . Mapping ) ;
468499 MessageBox . Show ( string . Format ( "Invalid TXPDO mapping parameters in 0x{0:X}!\r \n Trying to map more than the maximum lenght of a CAN message (8 bytes).\r \n \r \n Members are:\r \n {1}" , slot . ConfigurationIndex , toDisplay ) ) ;
469500 break ;
470501 }
471- string target = slot . getTargetName ( entry ) ;
472- grid1 [ row + 2 , bitoff + 3 ] = new SourceGrid . Cells . Cell ( target , comboStandard ) ;
473- grid1 [ row + 2 , bitoff + 3 ] . ColumnSpan = entry . Sizeofdatatype ( ) ;
474- grid1 [ row + 2 , bitoff + 3 ] . View = viewNormal ;
502+ string target = slot . getTargetName ( mappingentry . entry ) ;
503+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] = new SourceGrid . Cells . Cell ( target , comboStandard ) ;
504+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . ColumnSpan = mappingentry . width ;
505+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . View = viewNormal ;
506+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . ToolTipText = grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . DisplayText ;
475507
476- PDOlocator location = new PDOlocator ( ) ;
477- location . slot = slot ;
478- location . ordinal = ordinal ;
479- location . entry = entry ;
508+ PDOlocator location = new PDOlocator ( ) ;
509+ location . slot = slot ;
510+ location . ordinal = ordinal ;
511+ location . mappingentry = mappingentry ;
480512
481- Console . WriteLine ( string . Format ( "New location at Row {0} Col {1} Loc {2}" , row , bitoff , location . ToString ( ) ) ) ;
482- grid1 [ row + 2 , bitoff + 3 ] . Tag = location ;
513+ Console . WriteLine ( string . Format ( "New location at Row {0} Col {1} Loc {2}" , row , bitoff , location . ToString ( ) ) ) ;
514+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . Tag = location ;
483515
484- ValueChangedController vcc = new ValueChangedController ( ) ;
485- vcc . ValueChangedEvent += Vcc_ValueChangedEvent ;
516+ ValueChangedController vcc = new ValueChangedController ( ) ;
517+ vcc . ValueChangedEvent += Vcc_ValueChangedEvent ;
486518
487519
488- grid1 [ row + 2 , bitoff + 3 ] . AddController ( vcc ) ;
489- bitoff += entry . Sizeofdatatype ( ) ;
520+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . AddController ( vcc ) ;
521+ bitoff += mappingentry . width ;
490522
491523
492524 ordinal ++ ;
@@ -496,23 +528,24 @@ public void UpdatePDOinfo(bool updatechoices = true)
496528 //Pad out with an empty combo
497529 if ( bitoff < 64 )
498530 {
499- grid1 [ row + 2 , bitoff + 3 ] = new SourceGrid . Cells . Cell ( "Empty" , comboStandard ) ;
500- int colspan = 64 - bitoff ;
501- if ( colspan > 8 )
531+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] = new SourceGrid . Cells . Cell ( "Empty" , comboStandard ) ;
532+ // Align "Empty" cell to byte end
533+ int colspan = ( 64 - bitoff ) % 8 ;
534+ if ( ( colspan == 0 ) && ( ( 64 - bitoff ) > 8 ) )
502535 colspan = 8 ;
503- grid1 [ row + 2 , bitoff + 3 ] . ColumnSpan = colspan ;
504- grid1 [ row + 2 , bitoff + 3 ] . View = viewEmpty ;
536+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . ColumnSpan = colspan ;
537+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . View = viewEmpty ;
505538 ValueChangedController vcc = new ValueChangedController ( ) ;
506539 vcc . ValueChangedEvent += Vcc_ValueChangedEvent ;
507- grid1 [ row + 2 , bitoff + 3 ] . AddController ( vcc ) ;
540+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . AddController ( vcc ) ;
508541
509542 PDOlocator location = new PDOlocator ( ) ;
510543 location . slot = slot ;
511544 location . ordinal = ordinal ;
512- location . entry = null ;
545+ location . mappingentry . entry = null ;
513546
514547 Console . WriteLine ( string . Format ( "New location at Row {0} Col {1} Loc {2}" , row , bitoff , location . ToString ( ) ) ) ;
515- grid1 [ row + 2 , bitoff + 3 ] . Tag = location ;
548+ grid1 [ row + 2 , bitoff + INFO_COLS_COUNT ] . Tag = location ;
516549
517550
518551 }
@@ -523,12 +556,6 @@ public void UpdatePDOinfo(bool updatechoices = true)
523556 grid1 . VScrollBar . Value = savVScrollValue ;
524557 }
525558
526- private void ComboStandard_Changed ( object sender , EventArgs e )
527- {
528-
529-
530- }
531-
532559 public void redrawtable ( )
533560 {
534561
@@ -561,12 +588,12 @@ private class PDOlocator
561588 {
562589 public PDOSlot slot ;
563590 public int ordinal ;
564- public ODentry entry ;
591+ public PDOMappingEntry mappingentry ;
565592
566593 public override string ToString ( )
567594 {
568595 string msg ;
569- msg = String . Format ( "Ordinal {0} , slot {1} entry {2}" , ordinal , slot . ToString ( ) , entry == null ? "NULL" : entry . ToString ( ) ) ;
596+ msg = String . Format ( "Ordinal {0} , slot {1} entry {2}" , ordinal , slot . ToString ( ) , mappingentry . entry == null ? "NULL" : mappingentry . ToString ( ) ) ;
570597
571598 return msg ;
572599 }
@@ -581,27 +608,27 @@ private void clickEvent_Click(object sender, EventArgs e)
581608
582609 private void button_down_Click ( object sender , EventArgs e )
583610 {
584- int newwidth = grid1 . Columns [ 3 ] . Width - 10 ;
611+ int newwidth = grid1 . Columns [ INFO_COLS_COUNT ] . Width - 10 ;
585612 if ( newwidth < 18 )
586613 newwidth = 18 ;
587614
588615 Console . WriteLine ( "New Width " + newwidth . ToString ( ) ) ;
589616
590617 for ( int x = 0 ; x < 64 ; x ++ )
591618 {
592- grid1 . Columns [ x + 3 ] . Width = newwidth ;
619+ grid1 . Columns [ x + INFO_COLS_COUNT ] . Width = newwidth ;
593620 }
594621
595622 }
596623
597624 private void button_up_Click ( object sender , EventArgs e )
598625 {
599- int newwidth = grid1 . Columns [ 3 ] . Width + 10 ;
626+ int newwidth = grid1 . Columns [ INFO_COLS_COUNT ] . Width + 10 ;
600627 Console . WriteLine ( "New Width " + newwidth . ToString ( ) ) ;
601628
602629 for ( int x = 0 ; x < 64 ; x ++ )
603630 {
604- grid1 . Columns [ x + 3 ] . Width = newwidth ;
631+ grid1 . Columns [ x + INFO_COLS_COUNT ] . Width = newwidth ;
605632 }
606633
607634 }
@@ -696,7 +723,7 @@ private void grid1_DragDrop(object sender, DragEventArgs e)
696723
697724 foreach ( ODentry entry in entries )
698725 {
699- location . slot . insertMapping ( location . ordinal , entry ) ;
726+ location . slot . insertMapping ( location . ordinal , new PDOMappingEntry ( entry , entry . Sizeofdatatype ( ) ) ) ;
700727 }
701728
702729 helper . buildmappingsfromlists ( ( ExporterFactory . Exporter ) Properties . Settings . Default . ExporterType == ExporterFactory . Exporter . CANOPENNODE_V4 ) ;
0 commit comments