-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcamexpert.cpp
More file actions
3568 lines (1113 loc) · 51.9 KB
/
camexpert.cpp
File metadata and controls
3568 lines (1113 loc) · 51.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
************************************
*** @Xu Xu
*** @2017.05.10
*** @NanJing,China
*** @Hananiahhsu@live.cn
************************************
*/
#include "camexpert.h"
#include "ui_camexpert.h"
#include <QMessageBox>
#include <QCloseEvent>
#include <QtCore/qtextcodec.h>
#include <QTextCodec>
/// margin used to properly show piece in preview sheet @todo Add in option dialog
const int rectMarg=20;
CAMExpert::CAMExpert(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CAMExpert)
{
ui->setupUi(this);
//Get infos of screen
GetScreenInfos();
this->showMaximized();
QSize s(screen_w,screen_h);
this->resize(s);
//Management of signal and slots
CamSigSlotsManage();
//Manage the Dock win
CamDockWinManage();
//Create scene for plate(materials and part)
CreateScene();
//Layout many docks by myself
CamLayoutDocks();
//ini palette
errorText = QPalette(Qt::red,Qt::red,Qt::red,Qt::red,Qt::red,Qt::red,Qt::red,Qt::red,Qt::red);
successText = QPalette(Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue,Qt::darkBlue);
//right click signal for tableView of plate
connect(ui->Plate_tableView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(on_cam_right_menu_tableView(QPoint)));
//click the item of TableView
connect(ui->Plate_tableView,SIGNAL(clicked(QModelIndex)),this,SLOT(on_tableView_item_clicked()));
}
CAMExpert::~CAMExpert()
{
delete ui;
}
//===========================================
//Layout many docks-2017.6.2
//===========================================
void CAMExpert::CamLayoutDocks()
{
//tabifiedDockWidgets(ui->dockWidget_new_part);
tabifyDockWidget(ui->dockWidget_new_plate,ui->dockWidget_new_part);
tabifyDockWidget(ui->dockWidget_new_part,ui->dockWidget_property);
//tabPosition(Qt::TopDockWidgetArea);
}
//===========================================
//Get screen infos-2017.6.2
//===========================================
void CAMExpert::GetScreenInfos()
{
//Not the real dimension of screen but are the set value of display precision
QDesktopWidget * desk_widget = QApplication::desktop();
// QRect scr_rect = desk_widget->screenGeometry();
QRect desk_rect = desk_widget->availableGeometry();
screen_h = desk_rect.height();
screen_w = desk_rect.width();
}
//===========================================
//Create the scene-2017.6.1
//===========================================
void CAMExpert::CreateScene()
{
//********************New plate***************************************//
//(Here donnot use at all)
plate_scene = new CamScene(false);//meaning of false or true
plate_graphic_view = new QGraphicsView(plate_scene);
plate_graphic_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
plate_graphic_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//This is for previewing of plate(material)
plate_preView_scene = new CamScene();
plate_preView_scene->setSceneRect(0,0,300,200);
plate_graphics_preview = new QGraphicsView(plate_preView_scene);
plate_graphics_preview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
plate_graphics_preview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->gridLayout_3->addWidget(plate_graphics_preview);
//previewVS->addWidget(plate_graphics_preview);
//ui->dockWidget_3->setWidget(previewVS);
//*******************New Part**********************************************//
QSplitter *previewVS = new QSplitter(this);
previewVS->setOrientation(Qt::Vertical);//horizontal
//**TableView
QTableView *prt_tableView = new QTableView();
QRect prt_rect(1,300,276,232);
prt_tableView->setGeometry(prt_rect);
//Layout--no use
QGridLayout *prt_grid_layout = new QGridLayout;
prt_grid_layout->addWidget(prt_tableView);
//add widget to splitter
previewVS->addWidget(prt_tableView);
ui->dockWidget_new_part->setWidget(previewVS);
//ui->dockWidget_new_part->setLayout(prt_grid_layout);
//add buttons and spacers to docks--2017.6.2
QPushButton *btn_add_prt,*btn_new_prt;
btn_new_prt = new QPushButton(ui->dockWidget_new_part);
btn_new_prt->setText(QString::fromLocal8Bit("新建零件"));
btn_new_prt->setFixedHeight(25);
btn_new_prt->setGeometry(QRect(10,200,30,10));
btn_add_prt = new QPushButton(ui->dockWidget_new_part);
btn_add_prt->setText(QString::fromLocal8Bit("导入零件"));
btn_add_prt->setGeometry(QRect(50,200,30,10));
btn_add_prt->setFixedHeight(25);
//spcaers
QSpacerItem *prt_btn_spacer_1,*prt_btn_spacer_2,*prt_btn_spacer_3;
prt_btn_spacer_1 = new QSpacerItem(20,10,QSizePolicy::Expanding);
prt_btn_spacer_2 = new QSpacerItem(20,10,QSizePolicy::Expanding);
prt_btn_spacer_3 = new QSpacerItem(20,10,QSizePolicy::Expanding);
QSplitter *h_splitter = new QSplitter(ui->dockWidget_new_part);
h_splitter->addWidget(btn_new_prt);
h_splitter->addWidget(btn_add_prt);
previewVS->addWidget(h_splitter);
// QHBoxLayout * h_prt_layout = new QHBoxLayout();
// h_prt_layout->addWidget(btn_add_prt);
// ui->dockWidget_new_part->setLayout(h_prt_layout);
QObject::disconnect(prt_tableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(on_tablewidget_double_clicked(QModelIndex)));
//Add header acccording to model
model_prt_tableView = new QStandardItemModel();
model_prt_tableView->setColumnCount(8);
model_prt_tableView->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit("序号"));//QString::fromUtf8("序号")
model_prt_tableView->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit("长度"));
model_prt_tableView->setHeaderData(2,Qt::Horizontal,QString::fromLocal8Bit("宽度"));
model_prt_tableView->setHeaderData(3,Qt::Horizontal,QString::fromLocal8Bit("厚度"));
model_prt_tableView->setHeaderData(4,Qt::Horizontal,QString::fromLocal8Bit("数量"));
model_prt_tableView->setHeaderData(5,Qt::Horizontal,QString::fromLocal8Bit("材料"));
model_prt_tableView->setHeaderData(6,Qt::Horizontal,QString::fromLocal8Bit("编码"));
model_prt_tableView->setHeaderData(7,Qt::Horizontal,QString::fromLocal8Bit("旋转"));
//set the above model
prt_tableView->setModel(model_prt_tableView);
//Set the assignment of header information display mode as middle
prt_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
//Initialize the header of QTableWidget
prt_tableView->horizontalHeader()->setDefaultSectionSize(10);
//set the width of each column
prt_tableView->setColumnWidth(0,20);
prt_tableView->setColumnWidth(1,20);
prt_tableView->setColumnWidth(2,20);
prt_tableView->setColumnWidth(3,20);
prt_tableView->setColumnWidth(4,20);
prt_tableView->setColumnWidth(5,20);
prt_tableView->setColumnWidth(6,20);
prt_tableView->setColumnWidth(7,20);
//Resize the column to contents
prt_tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
prt_tableView->resizeRowsToContents();
//Grid style
prt_tableView->gridStyle();
//Hide the first col
QHeaderView *headerview = prt_tableView->verticalHeader();
headerview->setHidden(true);
//Display the lines
//Set the behavior of selection as row(you can set single selection or multi-row selection)
prt_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
prt_tableView->setSelectionMode(QAbstractItemView::MultiSelection);
//Right menu
prt_tableView->setContextMenuPolicy(Qt::CustomContextMenu);
//policy of scrollBar
prt_tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
prt_tableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//=============================================================================================
//Above widgets are QTableView and 2 QPushButtons
//Now under which i add a QGraphicsView
prt_preview_scene = new CamScene();
prt_preview_scene->setSceneRect(0,0,300,200);
prt_view = new QGraphicsView(prt_preview_scene);
prt_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
prt_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
previewVS->addWidget(prt_view);
//================================================================================================
//Connection for pushbutton of newprt
connect(btn_new_prt,SIGNAL(clicked(bool)),this,SLOT(on_new_prt_btn_newprt_clicked()));
connect(btn_add_prt,SIGNAL(clicked(bool)),this,SLOT(on_new_prt_btn_addprt_clicked()));
}
//===========================================
//Create a right menu for TableView of plate
//===========================================
void CAMExpert::createRightMenu()
{
right_menu = new QMenu;
QA_del_row = new QAction(QString::fromLocal8Bit("删除行"),this);
QA_copy_row = new QAction(QString::fromLocal8Bit("复制行"),this);
QA_paste_row = new QAction(QString::fromLocal8Bit("粘贴行"),this);
QA_cut_row = new QAction(QString::fromLocal8Bit("剪切行"),this);
right_menu->addAction(QA_del_row);
right_menu->addAction(QA_cut_row);
right_menu->addAction(QA_copy_row);
right_menu->addAction(QA_paste_row);
//CONNECT the action with main window
connect(QA_del_row,SIGNAL(triggered(bool)),this,SLOT(on_qa_del_row()));
connect(QA_copy_row,SIGNAL(triggered(bool)),this,SLOT(on_qa_copy_row()));
connect(QA_paste_row,SIGNAL(triggered(bool)),this,SLOT(on_qa_paste_row()));
connect(QA_cut_row,SIGNAL(triggered(bool)),this,SLOT(on_qa_cut_row()));
}
//===========================================
//Remove repeated index from TB_index_list
//===========================================
void CAMExpert::RemoveRepeatedIndex()
{
int row = -1,num = 0,data_num = 0;RowData data_row;
for(int i = 0;i < TB_index_list.size();i++)
{
for(int j = i+1;j < TB_index_list.size();j++)
{
if(TB_index_list[i].row() == TB_index_list[j].row())
{
num++;
row = TB_index_list[j].row();
}
}
}
if(num%2 == 1)
{
for(int i = 0;i < TB_index_list.size();i++)
{
if(row == TB_index_list[i].row())
{
//unselect the item of row ADN set the color to azure
model_plate_tableView->item(row,0)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,1)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,2)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,3)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,4)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,5)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,6)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(row,7)->setBackground(QBrush(QColor(240,255,255)));
TB_index_list.removeAt(i);
i--;
}
}
}
//For tb_data_list(2017.6.5)
for(int i = 0;i < TB_row_data_list.size();i++)
{
for(int j = i+1;j < TB_row_data_list.size();j++)
{
if(TB_row_data_list[j] == TB_row_data_list[i])
{
data_row = TB_row_data_list[j];
data_num++;
}
}
}
if(data_num%2 == 1)
{
for(int k = 0;k < TB_row_data_list.size();k++)
{
if(data_row == TB_row_data_list[k])
{
TB_row_data_list.removeAt(k); k--;
}
}
}
}
//===========================================
//Refresh the tableview after editting
//===========================================
void CAMExpert::RefreshTBIndex()
{
char *c_row;QByteArray arr_row; QString qs_row;
//model_plate_tableView->setSortRole(0);
model_plate_tableView->sort(0,Qt::AscendingOrder);
int row_num = model_plate_tableView->rowCount();
//reset the no of rows
for(int i = 0;i < row_num;i++)
{
qs_row = QString::number(i,10);
arr_row = qs_row.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(i,0,new QStandardItem(c_row));
model_plate_tableView->item(i,0)->setTextAlignment(Qt::AlignCenter);
//set the color
model_plate_tableView->item(i,0)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,1)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,2)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,3)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,4)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,5)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,6)->setBackground(QBrush(QColor(240,255,255)));
model_plate_tableView->item(i,7)->setBackground(QBrush(QColor(240,255,255)));
}
}
//===========================================
//Del,cut,copy or paste a row of tableView
//===========================================
void CAMExpert::TableViewDelRow()
{
for(int i = 0;i < TB_index_list.size();i++)
{
//the param should be row(),not i instead
model_plate_tableView->removeRow(TB_index_list[i].row());
}
//After you delete the above rows,please remove the data in TB_index_list
for(int j = 0;j < TB_index_list.size();j++)
{
TB_index_list.removeAt(j); j--;
}
}
void CAMExpert::TableViewCutRow()
{
//Cut-->copy the row to QList,then del the row
for(int i = 0;i < TB_index_list.size();i++)
{
TB_cut_template.append(TB_index_list[i]);
}
//First clear TB_row_data_list
TB_row_data_cut_list.clear();
for(int i = 0;i < TB_row_data_list.size();i++)
{
TB_row_data_cut_list.append(TB_row_data_list[i]);
}
TableViewDelRow();
}
void CAMExpert::TableViewCopyRow()
{
TB_row_data_cpy_list.clear();
for(int i = 0;i < TB_row_data_list.size();i++)
{
TB_row_data_cpy_list.append(TB_row_data_list[i]);
}
}
void CAMExpert::TableViewPasteRow()
{
int row = 0;QString qs_row;char *c_row;QByteArray arr_row;
//There are 2 cases for pasting,one from cutting,another from copy
//case 1:From cutting
if(!TB_row_data_cut_list.isEmpty())
{
//paste the items from TB_cut_template to current model
for(int i = 0;i < TB_row_data_cut_list.size();i++)
{
row = model_plate_tableView->rowCount();
qs_row = QString::number(row,10);
arr_row = qs_row.toLatin1();
c_row = arr_row.data();
//paste datas from TB_cut_template to current model
model_plate_tableView->setItem(row,0,new QStandardItem(c_row));
model_plate_tableView->item(row,0)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_1.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,1,new QStandardItem(c_row));
model_plate_tableView->item(row,1)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_2.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,2,new QStandardItem(c_row));
model_plate_tableView->item(row,2)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_3.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,3,new QStandardItem(c_row));
model_plate_tableView->item(row,3)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_4.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,4,new QStandardItem(c_row));
model_plate_tableView->item(row,4)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_5.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,5,new QStandardItem(c_row));
model_plate_tableView->item(row,5)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_6.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,6,new QStandardItem(c_row));
model_plate_tableView->item(row,6)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cut_list[i].row_v_7.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,7,new QStandardItem(c_row));
model_plate_tableView->item(row,7)->setTextAlignment(Qt::AlignCenter);
}
}
//case 2:from copying
if(!TB_row_data_cpy_list.isEmpty())
{
for(int j = 0;j < TB_row_data_cpy_list.size();j++)
{
row = model_plate_tableView->rowCount();
qs_row = QString::number(row,10);
arr_row = qs_row.toLatin1();
c_row = arr_row.data();
//paste datas from TB_cut_template to current model
model_plate_tableView->setItem(row,0,new QStandardItem(c_row));
model_plate_tableView->item(row,0)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_1.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,1,new QStandardItem(c_row));
model_plate_tableView->item(row,1)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_2.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,2,new QStandardItem(c_row));
model_plate_tableView->item(row,2)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_3.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,3,new QStandardItem(c_row));
model_plate_tableView->item(row,3)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_4.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,4,new QStandardItem(c_row));
model_plate_tableView->item(row,4)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_5.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,5,new QStandardItem(c_row));
model_plate_tableView->item(row,5)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_6.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,6,new QStandardItem(c_row));
model_plate_tableView->item(row,6)->setTextAlignment(Qt::AlignCenter);
arr_row = TB_row_data_cpy_list[j].row_v_7.toLatin1();
c_row = arr_row.data();
model_plate_tableView->setItem(row,7,new QStandardItem(c_row));
model_plate_tableView->item(row,7)->setTextAlignment(Qt::AlignCenter);
}
}
}
//======================================
//Management of sig and slots
//======================================
void CAMExpert::CamSigSlotsManage()
{
QObject::connect(ui->pushButton_NewMat,SIGNAL(clicked()),this,SLOT(on_pushButton_NewMat_clicked()));
QObject::connect(ui->pushButton_importMat,SIGNAL(clicked()),this,SLOT(on_pushButton_importMat_clicked()));
//The connect action must be behind the instance of CAM_NEWMAT_WIN or CAM_IMPORT_WIN
if(1 == cam_impmat_show_times)
{
QObject::connect(CAM_IMPORT_WIN,SIGNAL(destroyed()),this,SLOT(on_cam_importmat_win_destroy()));
}
if(1 == cam_newmat_show_times)
{
QObject::connect(CAM_NEWMAT_WIN,SIGNAL(destroyed(CAM_NEWMAT_WIN)),this,SLOT(on_cam_newmat_win_destroy()));
}
}
//======================================
//Management of dock windows
//======================================
void CAMExpert::CamDockWinManage()
{
//QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
//************************Init of QTableView***************************//
//Note:TableView a little different with Table Widget
QObject::disconnect(ui->Plate_tableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(on_tablewidget_double_clicked(QModelIndex)));
//Add header acccording to model
model_plate_tableView = new QStandardItemModel();
model_plate_tableView->setColumnCount(8);
model_plate_tableView->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit("序号"));//QString::fromUtf8("序号")
model_plate_tableView->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit("长度"));
model_plate_tableView->setHeaderData(2,Qt::Horizontal,QString::fromLocal8Bit("宽度"));
model_plate_tableView->setHeaderData(3,Qt::Horizontal,QString::fromLocal8Bit("厚度"));
model_plate_tableView->setHeaderData(4,Qt::Horizontal,QString::fromLocal8Bit("数量"));
model_plate_tableView->setHeaderData(5,Qt::Horizontal,QString::fromLocal8Bit("材料"));
model_plate_tableView->setHeaderData(6,Qt::Horizontal,QString::fromLocal8Bit("编码"));
model_plate_tableView->setHeaderData(7,Qt::Horizontal,QString::fromLocal8Bit("消耗量"));
//set the above model
ui->Plate_tableView->setModel(model_plate_tableView);
//Set the assignment of header information display mode as middle
ui->Plate_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
//Initialize the header of QTableWidget
ui->Plate_tableView->horizontalHeader()->setDefaultSectionSize(10);
QRect plate_rect(0,0,298,200);
ui->Plate_tableView->setGeometry(plate_rect);
//set the width of each column
ui->Plate_tableView->setColumnWidth(0,20);
ui->Plate_tableView->setColumnWidth(1,20);
ui->Plate_tableView->setColumnWidth(2,20);
ui->Plate_tableView->setColumnWidth(3,20);
ui->Plate_tableView->setColumnWidth(4,20);
ui->Plate_tableView->setColumnWidth(5,20);
ui->Plate_tableView->setColumnWidth(6,20);
ui->Plate_tableView->setColumnWidth(7,20);
//Resize the column to contents
//ui->Plate_tableView->horizontalHeader()->setStretchLastSection(true);
ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(2,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(4,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(5,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(6,QHeaderView::ResizeToContents);
// ui->Plate_tableView->horizontalHeader()->setSectionResizeMode(7,QHeaderView::ResizeToContents);
ui->Plate_tableView->resizeRowsToContents();
//ui->Plate_tableView->resizeColumnsToContents();
//Grid style
ui->Plate_tableView->gridStyle();
//Hide the first col
QHeaderView *headerview = ui->Plate_tableView->verticalHeader();
headerview->setHidden(true);
//Display the lines
//Set the behavior of selection as row(you can set single selection or multi-row selection)
ui->Plate_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->Plate_tableView->setSelectionMode(QAbstractItemView::MultiSelection);
//Disable the editing of tableWidget(if not set,then it's editable by default)
//ui->Plate_tableView->setEditTriggers(QAbstractItemView::EditTriggers);
//Right menu
ui->Plate_tableView->setContextMenuPolicy(Qt::CustomContextMenu);
createRightMenu();
//QStringList header;
//header << "序号(No.)" << "长(L)" << "宽(W)" << "厚度(T)" << "数量(Q)" << "材料(M)" << "编码(C)" << "消耗量(CP)";
//ui->Plate_tableView->setHorizontalHeaderLabels(header);
//ui->Plate_tableView->horizontalHeader()->setStretchLastSection(true);//fill the whole table
//After select multi-rows,right click and delete
}
//======================================
//close event
//======================================
void CAMExpert::closeEvent(QCloseEvent *event)
{
event->accept();
}
//======================================
//process event
//======================================
void CAMExpert::customEvent(QEvent * event,QObject * obj)
{
if(event->type() == QEvent::Destroy)
{
cam_impmat_show_times = 0;
cam_newmat_show_times = 0;
}
}
//======================================
//Slot of Files
//======================================
void CAMExpert::on_new_order_triggered()
{
QMessageBox::information(this,"title","New_order");
}
void CAMExpert::on_save_order_triggered()
{
QMessageBox::information(this,"title","save_order");
}
void CAMExpert::on_history_order_triggered()
{
QMessageBox::information(this,"title","history_order");
}
void CAMExpert::on_import_2_triggered()
{
QMessageBox::information(this,"title","import");
}
void CAMExpert::on_export_2_triggered()
{
QMessageBox::information(this,"title","export");
}
void CAMExpert::on_quit_triggered()
{
QApplication::quit();
}
//======================================
//Slot of Nest
//======================================
void CAMExpert::on_new_mat_triggered()
{
//QMessageBox::information(this,"title","New_mat");
//Toggle to dock of new palte(2017.6.7)
ui->dockWidget_new_plate->raise();
on_pushButton_NewMat_clicked();
}
void CAMExpert::on_new_layout_triggered()
{
QMessageBox::information(this,"title","New_layout");
}
void CAMExpert::on_new_prt_triggered()
{
//QMessageBox::information(this,"title","New_prt");
//Toggle to dock of new parts(2017.6.7)
ui->dockWidget_new_part->raise();
on_new_prt_btn_newprt_clicked();
}
void CAMExpert::on_run_triggered()
{
QMessageBox::information(this,"title","run_nest");
}
void CAMExpert::on_print_preview_triggered()
{
QMessageBox::information(this,"title","print preview");
}
void CAMExpert::on_print_triggered()
{
QMessageBox::information(this,"title","print");
}
void CAMExpert::on_send_triggered()
{
QMessageBox::information(this,"title","send to factory");
}
//======================================
//Slot of Layout
//======================================
void CAMExpert::on_open_layout_triggered()
{
QMessageBox::information(this,"title","open layout");
}
void CAMExpert::on_print_layout_triggered()
{
QMessageBox::information(this,"title","print layout");
}
void CAMExpert::on_open_all_layout_triggered()
{
QMessageBox::information(this,"title","print all layout");
}
//======================================
//Slot of KBE
//======================================
void CAMExpert::on_equipments_triggered()
{
QMessageBox::information(this,"title","equip lib");
}
void CAMExpert::on_materials_triggered()
{
QMessageBox::information(this,"title","mat lib");
}
void CAMExpert::on_manufs_triggered()
{
QMessageBox::information(this,"title","tech lib");
}
//======================================
//Slot of Tools
//======================================
void CAMExpert::on_cost_triggered()
{
QMessageBox::information(this,"title","cost");
}
void CAMExpert::on_calculator_triggered()
{
QMessageBox::information(this,"title","calculator");
}
//======================================
//Slot of Help
//======================================
void CAMExpert::on_about_triggered()
{
QMessageBox::information(this,"title","about");
}
void CAMExpert::on_help_files_triggered()
{
QMessageBox::information(this,"title","help files");
}
//======================================
//Slot of Drawing
//======================================
void CAMExpert::on_Line_triggered()
{
QMessageBox::information(this,"title","line");
}
void CAMExpert::on_Arc_triggered()
{
QMessageBox::information(this,"title","arc");
}
void CAMExpert::on_Text_triggered()
{
QMessageBox::information(this,"title","text");
}
void CAMExpert::on_Circle_triggered()
{
QMessageBox::information(this,"title","circle");
}
void CAMExpert::on_Ellipse_triggered()
{
QMessageBox::information(this,"title","Ellipse");
}
void CAMExpert::on_Polygon_triggered()
{
QMessageBox::information(this,"title","polygon");
}
void CAMExpert::on_Copy_triggered()
{
QMessageBox::information(this,"title","copy");
}
void CAMExpert::on_Dimension_triggered()
{
QMessageBox::information(this,"title","dimension");
}
void CAMExpert::on_Choose_triggered()
{
QMessageBox::information(this,"title","choose");
}
void CAMExpert::on_Translation_triggered()
{
QMessageBox::information(this,"title","translation");
}
void CAMExpert::on_Rotation_triggered()
{
QMessageBox::information(this,"title","Rotation");
}
void CAMExpert::on_Delete_triggered()
{
QMessageBox::information(this,"title","Delete");
}
void CAMExpert::on_Offset_triggered()
{
QMessageBox::information(this,"title","offset");
}
void CAMExpert::on_Line_Color_triggered()
{
QMessageBox::information(this,"title","Line color");
}
void CAMExpert::on_Line_Type_triggered()
{
QMessageBox::information(this,"title","Line type");
}
void CAMExpert::on_Line_Width_triggered()
{
QMessageBox::information(this,"title","Line width");
}
//======================================
//Slot of pushButtons
//======================================
//New mat by choosing the mat from local text
//If mat not found,you may add it too
void CAMExpert::on_pushButton_NewMat_clicked()
{
if(cam_newmat_show_times == 0)
{
CAM_NEWMAT_WIN = new CAM_NewMaterial;
CAM_NEWMAT_WIN->setAttribute(Qt::WA_DeleteOnClose);
CAM_NEWMAT_WIN->setGeometry(QRect(490,150,510,140));//6.7
CAM_NEWMAT_WIN->show();
//The instance of import win must be realized before connectting signal and slots
QObject::connect(CAM_NEWMAT_WIN,SIGNAL(destroyed()),this,SLOT(on_cam_newmat_win_destroy()));
//Get the name and thickness of mat from CAM_NEWMAT_WIN(before destroyed)
//2017.6.5-NIGHT--close the Close Signal and use button to send signal from CAM_NEWMAT_WIN
//QObject::connect(CAM_NEWMAT_WIN,SIGNAL(CAM_NewMat_Close_Signal(QString,QString)),this,SLOT(on_cam_newmat_win_receiveData(QString,QString)));
QObject::connect(CAM_NEWMAT_WIN,SIGNAL(CAM_NewMat_New_Signal(QString,QString)),this,SLOT(on_cam_newmat_win_receiveData(QString,QString)));
//2017.6.6-connect add pushbutton with dock win
QObject::connect(CAM_NEWMAT_WIN,SIGNAL(CAM_AddMat_Add_Signal(QString,QString)),this,SLOT(on_cam_newmat_win_receiveData(QString,QString)));
}
cam_newmat_show_times++;
}
//Import mat from the DXF file(Here could be connected with database)
//Later other format of files may be imported too
void CAMExpert::on_pushButton_importMat_clicked()
{
if(cam_impmat_show_times == 0)
{
CAM_IMPORT_WIN = new CAM_ImportMat;
CAM_IMPORT_WIN->setAttribute(Qt::WA_DeleteOnClose);
CAM_IMPORT_WIN->show();
//The instance of import win must be realized before connectting signal and slots
QObject::connect(CAM_IMPORT_WIN,SIGNAL(CAM_ImportMat_Close_Signal(QStringList)),this,SLOT(on_cam_importmat_win_destroy()));
//After choosing a dxf file,reset the value of cam_impmat_show_times too
QObject::connect(CAM_IMPORT_WIN,SIGNAL(fileSelected(QString)),this,SLOT(on_cam_importmat_win_destroy()));
QObject::connect(CAM_IMPORT_WIN,SIGNAL(destroyed(QObject*)),this,SLOT(on_cam_importmat_win_destroy()));
/*
//The follwing window closed,it's hard to get the sig,so use another way(also failed-2017.5.25)
//CamOpenDxfFile(QFileDialog::getOpenFileName(CAM_IMPORT_WIN,"导入材料",".","DXF FILES (*.dxf)"));
//Alternative way of open file
DXF_WIN = new QFileDialog(this);
DXF_WIN->setWindowTitle(tr("导入材料"));
DXF_WIN->setDirectory("/");
DXF_WIN->setFilter(QDir::Files|QDir::NoSymLinks|QDir::AllDirs);
//As DXF_WIN destroyed
QObject::connect(DXF_WIN,SIGNAL(directoryEntered(QString)),this,SLOT(on_cam_importmat_win_destroy()));
if(DXF_WIN->exec() == QFileDialog::Accepted)
{
QString dxf_path = DXF_WIN->selectedFiles()[0];
}
*/
QObject::connect(CAM_IMPORT_WIN,SIGNAL(CAM_ImportMat_Close_Signal(QStringList)),this,SLOT(on_cam_importmat_win_receiveData(QStringList)));
QObject::connect(CAM_IMPORT_WIN,SIGNAL(fileSelected(QString)),this,SLOT(on_cam_importmat_win_openfiles(QString)));
}
cam_impmat_show_times++;
}
//Set the value to 0 again after killing the child window
void CAMExpert::on_cam_importmat_win_destroy()
{
cam_impmat_show_times = 0;
}
void CAMExpert::on_cam_newmat_win_destroy()
{
cam_newmat_show_times = 0;
}
void CAMExpert::on_cam_newprt_win_destroyed()
{
cam_newprt_show_times = 0;
}
void CAMExpert::on_cam_impprt_win_destroyed()
{
cam_impprt_show_times = 0;
}
//slots of TableView of plate
void CAMExpert::on_cam_newmat_win_receiveData(QString qs_name,QString qs_thick)
{
//int converted to QString
int row = model_plate_tableView->rowCount();
QString qs_row = QString::number(row,10);
char *c_row;
QByteArray arr_row = qs_row.toLatin1();
c_row = arr_row.data();
//receive datas from new_mat window to tableView
model_plate_tableView->setItem(row,0,new QStandardItem(c_row));
model_plate_tableView->item(row,0)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,1,new QStandardItem("100"));
model_plate_tableView->item(row,1)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,2,new QStandardItem("50"));
model_plate_tableView->item(row,2)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,3,new QStandardItem(qs_thick));
model_plate_tableView->item(row,3)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,4,new QStandardItem("1"));
model_plate_tableView->item(row,4)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,5,new QStandardItem(qs_name));
model_plate_tableView->item(row,5)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,6,new QStandardItem(""));
model_plate_tableView->item(row,6)->setTextAlignment(Qt::AlignCenter);
model_plate_tableView->setItem(row,7,new QStandardItem("1"));
model_plate_tableView->item(row,7)->setTextAlignment(Qt::AlignCenter);
}
/**************************************
* Slot for new prt in dock of new prt
**************************************/
void CAMExpert::on_new_prt_btn_newprt_clicked()
{
if(cam_newprt_show_times == 0)
{
//new dialog
CAM_NEWPRT_WIN = new CAM_NewPrt();
CAM_NEWPRT_WIN->setAttribute(Qt::WA_DeleteOnClose);//6.6
CAM_NEWPRT_WIN->setGeometry(QRect(450,150,230,320));
CAM_NEWPRT_WIN->setFixedHeight(320);
CAM_NEWPRT_WIN->setFixedWidth(230);
cam_newprt_win_icon.addFile(QStringLiteral(":/rec/Resource/company/wit.png"), QSize(), QIcon::Normal, QIcon::Off);
CAM_NEWPRT_WIN->setWindowIcon(cam_newprt_win_icon);
CAM_NEWPRT_WIN->setWindowTitle(QString::fromLocal8Bit("新建零件"));
CAM_NEWPRT_WIN->setModal(true);//set before showing
CAM_NEWPRT_WIN->show();
//connect self defined signals
connect(CAM_NEWPRT_WIN,SIGNAL(CAM_NewPrt_Destroy()),this,SLOT(on_cam_newprt_win_destroyed()));