-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModelViewerView.cpp
More file actions
3688 lines (3268 loc) · 159 KB
/
ModelViewerView.cpp
File metadata and controls
3688 lines (3268 loc) · 159 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
#include "pch.h"
#include <stdio.h>
#include "framework.h"
#ifndef SHARED_HANDLERS
#include "ModelViewer.h"
#endif
#include "ModelViewerDoc.h"
#include "ModelViewerView.h"
#include "MainFrm.h"
#include "CAvroView.h"
#include "ViewTreeEntity.h"
#include "ViewTreeAvro.h"
#include "CDialogAvro.h"
#include "CDialogLookAt.h"
#include "CDialogShapePoint.h"
#include "CDialogShapeEdgeStraight.h"
#include "CDialogShapeFaceCone.h"
#include "CDialogShapeFacePlane.h"
#include "LoadStlFile.h"
#include "setting.h"
#include "utility/json/json11util.hpp"
// START FR
//#include "recognized_welding_result.h"
#include "avro_fr_utility.hpp"
// END FR
// START ACIS
#include "ga_api.hxx"
#include "cstrapi.hxx"
#include "kernapi.hxx"
#include "acistype.hxx"
#include "rnd_api.hxx"
#include "rgbcolor.hxx"
#include "edge.hxx"
#include "vertex.hxx"
#include "point.hxx"
#include "unitvec.hxx"
#include "boolapi.hxx"
// END ACIS
#include <boost/filesystem.hpp>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "CDialogApiSubtract.h"
// CModelViewerView
IMPLEMENT_DYNCREATE(CModelViewerView, COpenGLPickView)
BEGIN_MESSAGE_MAP(CModelViewerView, COpenGLPickView)
// 標準印刷コマンド
//ON_COMMAND(ID_FILE_PRINT, &COpenGLPickView::OnFilePrint)
//ON_COMMAND(ID_FILE_PRINT_DIRECT, &COpenGLPickView::OnFilePrint)
//ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CModelViewerView::OnFilePrintPreview)
//ON_WM_CONTEXTMENU()
//ON_WM_RBUTTONUP()
ON_COMMAND(ID_VIEW_ROTATION, &CModelViewerView::OnViewRotation)
ON_COMMAND(ID_VIEW_PAN, &CModelViewerView::OnViewPan)
ON_COMMAND(ID_VIEW_ZOOM, &CModelViewerView::OnViewZoom)
ON_UPDATE_COMMAND_UI(ID_VIEW_ROTATION, &CModelViewerView::OnUpdateViewRotation)
ON_UPDATE_COMMAND_UI(ID_VIEW_PAN, &CModelViewerView::OnUpdateViewPan)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM, &CModelViewerView::OnUpdateViewZoom)
ON_COMMAND(ID_VIEW_RENDERPOINT, &CModelViewerView::OnViewRenderpoint)
ON_COMMAND(ID_VIEW_RENDERLINE, &CModelViewerView::OnViewRenderline)
ON_COMMAND(ID_VIEW_RENDERFACE, &CModelViewerView::OnViewRenderface)
ON_UPDATE_COMMAND_UI(ID_VIEW_RENDERPOINT, &CModelViewerView::OnUpdateViewRenderpoint)
ON_UPDATE_COMMAND_UI(ID_VIEW_RENDERLINE, &CModelViewerView::OnUpdateViewRenderline)
ON_UPDATE_COMMAND_UI(ID_VIEW_RENDERFACE, &CModelViewerView::OnUpdateViewRenderface)
ON_COMMAND(ID_VIEW_PICKPOINT, &CModelViewerView::OnViewPickpoint)
ON_COMMAND(ID_VIEW_PICKLINE, &CModelViewerView::OnViewPickline)
ON_COMMAND(ID_VIEW_PICKFACE, &CModelViewerView::OnViewPickface)
ON_UPDATE_COMMAND_UI(ID_VIEW_PICKPOINT, &CModelViewerView::OnUpdateViewPickpoint)
ON_UPDATE_COMMAND_UI(ID_VIEW_PICKLINE, &CModelViewerView::OnUpdateViewPickline)
ON_UPDATE_COMMAND_UI(ID_VIEW_PICKFACE, &CModelViewerView::OnUpdateViewPickface)
//ON_COMMAND(ID_FILE_OPEN, &CModelViewerView::OnFileOpen)
ON_COMMAND(ID_FILE_NEW, &CModelViewerView::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CModelViewerView::OnFileOpenSat)
ON_COMMAND(ID_FILE_OPEN_ADD, &CModelViewerView::OnFileOpenAddSat)
ON_COMMAND(ID_FILE_OPEN_AVRO, &CModelViewerView::OnFileOpenAvro)
ON_COMMAND(ID_FILE_OPEN_JSON, &CModelViewerView::OnFileOpenJson)
ON_COMMAND(ID_FILE_SAVE_AS, &CModelViewerView::OnFileSaveAs)
ON_COMMAND(ID_LOOKAT_CENTER, &CModelViewerView::OnSetLookAtCenter)
ON_COMMAND(ID_SHAPE_POINT, &CModelViewerView::OnShapePoint)
ON_COMMAND(ID_SHAPE_EDGE_STRAIGHT, &CModelViewerView::OnShapeEdgeStraight)
ON_COMMAND(ID_SHAPE_EDGE_ELLIPSE, &CModelViewerView::OnShapeEdgeEllipse)
ON_COMMAND(ID_SHAPE_FACE_CONE, &CModelViewerView::OnShapeFaceCone)
ON_COMMAND(ID_SHAPE_FACE_PLANE, &CModelViewerView::OnShapeFacePlane)
ON_COMMAND(ID_SHAPE_FACE_SPHERE, &CModelViewerView::OnShapeFaceSphere)
ON_COMMAND(ID_SHAPE_FACE_SPLINE, &CModelViewerView::OnShapeFaceSpline)
ON_COMMAND(ID_SHAPE_FACE_TORUS, &CModelViewerView::OnShapeFaceTorus)
ON_COMMAND(ID_SHAPE_SOLID_BLOCK, &CModelViewerView::OnShapeSolidBlock)
ON_COMMAND(ID_SHAPE_SOLID_CYLINDER, &CModelViewerView::OnShapeSolidCylinder)
ON_COMMAND(ID_SHAPE_SOLID_SPHERE, &CModelViewerView::OnShapeSolidSphere)
ON_COMMAND(ID_SHAPE_SOLID_TORUS, &CModelViewerView::OnShapeSolidTorus)
ON_COMMAND(ID_API_SUBTRACT, &CModelViewerView::OnApiSubtract)
ON_COMMAND(ID_API_UNITE, &CModelViewerView::OnApiUnite)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_BN_CLICKED(IDOK, &CModelViewerView::OnApiSubtractBnClickedOk)
END_MESSAGE_MAP()
// CModelViewerView コンストラクション/デストラクション
CModelViewerView::CModelViewerView() :
m_bRotation(TRUE),
m_bPan(TRUE),
m_bZoom(TRUE),
m_bRenderPoint(TRUE),
m_bRenderLine(TRUE),
m_bRenderFace(TRUE),
m_bPickPoint(TRUE),
m_bPickLine(TRUE),
m_bPickFace(TRUE)
{
m_fLineWidth = Setting::Line_Width; // Lineサイズ
m_fPointSize = Setting::Point_Size; // 頂点サイズ
m_fFaceAlpha = Setting::Face_Alpha; // Face透明度
m_fLineAlpha = Setting::Line_Alpha; // Line透明度
m_fPointAlpha = Setting::Point_Alpha; // 頂点透明度
}
CModelViewerView::~CModelViewerView()
{
if (m_display_data)
{
delete m_display_data;
m_display_data = nullptr;
}
for (int i=0;i< m_pmi_list.size();++i)
{
if (m_pmi_list[i])
{
delete m_pmi_list[i];
}
}
}
BOOL CModelViewerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: この位置で CREATESTRUCT cs を修正して Window クラスまたはスタイルを
// 修正してください。
return COpenGLPickView::PreCreateWindow(cs);
}
// CModelViewerView 描画
//void CModelViewerView::OnDraw(CDC* /*pDC*/)
//{
// CModelViewerDoc* pDoc = GetDocument();
// ASSERT_VALID(pDoc);
// if (!pDoc)
// return;
//
// // TODO: この場所にネイティブ データ用の描画コードを追加します。
//}
// CModelViewerView の印刷
void CModelViewerView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CModelViewerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 既定の印刷準備
return DoPreparePrinting(pInfo);
}
void CModelViewerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 印刷前の特別な初期化処理を追加してください。
}
void CModelViewerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 印刷後の後処理を追加してください。
}
void CModelViewerView::ReadSatFile(bool is_add)
{
CFileDialog file_open_dialog(TRUE);
file_open_dialog.m_ofn.lpstrFilter = _T("SAT ファイル (*.sat)\0*.sat\0")
_T("All Files (*.*)\0*.*\0\0");
file_open_dialog.m_ofn.nFilterIndex = 1;
file_open_dialog.m_ofn.Flags |= OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
INT_PTR iResponse = file_open_dialog.DoModal();
if (iResponse == IDOK)
{
char* sat_file_name;
size_t length = wcslen(file_open_dialog.GetPathName().GetBuffer()) + 1;
sat_file_name = (LPSTR)malloc(length * sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, // CODE PAGE: ANSI code page
0,
file_open_dialog.GetPathName().GetBuffer(),
-1,
sat_file_name,
(int)length * sizeof(WCHAR),
NULL,
NULL);
ENTITY_LIST read_sat_file; // 読み込むSATファイルENTITY_LIST
// SAT読み込み処理
RestoreSAT(sat_file_name, read_sat_file);
// 追加読み込む処理チェック
if (!is_add)
{
m_entity_list.clear();
}
m_entity_list.add(read_sat_file);
if (m_display_data)
{
delete m_display_data;
m_display_data = nullptr;
}
m_display_data = new AcisMesh::DisplayData;
if (CreateMeshFromEntityList(m_entity_list, *m_display_data, m_selected_list, m_pmi_list))
{
boost::filesystem::path path(sat_file_name);
CreateEnitiyTreeItems(read_sat_file, path.filename().string(), is_add);
}
SetEntityMap(m_entity_list);
}
}
void CModelViewerView::SetEntityMap(ENTITY_LIST& entity_list)
{
m_uid_to_face_map.clear();
for (int i = 0; i < m_entity_list.count(); ++i)
{
ENTITY_LIST faces;
api_get_faces(m_entity_list[i], faces);
for (int j = 0; j < faces.count(); ++j)
{
std::string str_uid = find_attribute(faces[j], "uid");
if (!str_uid.empty())
{
m_uid_to_face_map.insert(std::make_pair(str_uid, faces[j]));
}
}
}
m_uid_to_edge_map.clear();
for (int i = 0; i < m_entity_list.count(); ++i)
{
ENTITY_LIST edges;
api_get_edges(m_entity_list[i], edges);
for (int j = 0; j < edges.count(); ++j)
{
std::string str_uid = find_attribute(edges[j], "uid");
if (!str_uid.empty())
{
m_uid_to_edge_map.insert(std::make_pair(str_uid, edges[j]));
}
}
}
m_uid_to_vertex_map.clear();
for (int i = 0; i < m_entity_list.count(); ++i)
{
ENTITY_LIST vertices;
api_get_vertices(m_entity_list[i], vertices);
for (int j = 0; j < vertices.count(); ++j)
{
std::string str_uid = find_attribute(vertices[j], "uid");
if (!str_uid.empty())
{
m_uid_to_vertex_map.insert(std::make_pair(str_uid, vertices[j]));
}
}
}
}
COGLJText* CModelViewerView::CreatePMI(AcisMesh::EdgeVertex edgeVertex)
{
COGLJText* point_text = new COGLJText(_T("Meiryo UI"), 8, COGLJText::OP_LEFTTOP);
point_text->Format(_T("%6.3f,%6.3f,%6.3f"), edgeVertex.x, edgeVertex.y, edgeVertex.z);
return point_text;
}
COGLJText* CModelViewerView::CreateEdgePMI(ENTITY* edge)
{
COGLJText* point_text = nullptr;
if (is_EDGE(edge))
{
const float fFontSize = 14.0f;
point_text = new COGLJText(_T("Meiryo UI"), fFontSize, COGLJText::OP_LEFTTOP);
point_text->Format(_T("%6.3f"), ((EDGE*)edge)->length());
}
return point_text;
}
COGLJText* CModelViewerView::CreateVertexPMI(double vertex[3])
{
COGLJText* point_text = nullptr;
const float fFontSize = 14.0f;
point_text = new COGLJText(_T("Meiryo UI"), fFontSize, COGLJText::OP_LEFTTOP);
point_text->Format(_T("%6.3f,%6.3f,%6.3f"), vertex[0], vertex[1], vertex[2]);
return point_text;
}
static void CheckChild(CTreeCtrl* pTree, HTREEITEM hParent, BOOL bCheck)
{
HTREEITEM hItem = pTree->GetChildItem(hParent);
while (hItem != NULL)
{
pTree->SetCheck(hItem, bCheck);
CheckChild(pTree, hItem, bCheck);
hItem = pTree->GetNextItem(hItem, TVGN_NEXT);
}
}
void CModelViewerView::CreateEnitiyTreeItems(const ENTITY_LIST& entity_list, std::string file_name, bool is_add)
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
// 追加読み込みチェック
if (!is_add)
{
pFrame->m_wndEntityView.m_wndEntityView.DeleteAllItems();
}
auto get_tree_item_name = [](ENTITY* ent, const int ent_index, const int children_size)
{
std::string entity_name = "ENTITY";
if (is_BODY(ent))
{
entity_name = "BODY";
}
else if (is_FACE(ent))
{
entity_name = "FACE";
}
else if (is_EDGE(ent))
{
entity_name = "EDGE";
}
else if (is_VERTEX(ent))
{
entity_name = "VERTEX";
}
char str[255] = "\0";
std::string uid = find_attribute(ent, "uid");
if (strlen(uid.c_str()))
{
sprintf_s(str, "%s%03d %s(%d)", entity_name.c_str(), ent_index, uid.c_str(), children_size);
}
else
{
sprintf_s(str, "%s%03d(%d)", entity_name.c_str(), ent_index, children_size);
}
return std::string(str);
};
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, file_name.c_str(), data_size, w_str, data_size + 1);
HTREEITEM hRoot = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 0, 0);
pFrame->m_wndEntityView.m_wndEntityView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
std::string entity_name;
// entity階層
for (int i = 0; i < entity_list.count(); ++i)
{
HTREEITEM hBody;
if (is_BODY(entity_list[i]))
{
sprintf_s(str, "BODY");
}
else
{
sprintf_s(str, "NonBODY");
}
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
hBody = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, hRoot);
ENTITY_LIST faces;
api_get_faces(entity_list[i], faces);
int faces_count = faces.count();
if (faces_count > 0)
{
// face子階層
for (int j = 0; j < faces_count; ++j)
{
ENTITY_LIST edges;
api_get_edges(faces[j], edges);
int edges_count = edges.count();
entity_name = get_tree_item_name(faces[j], j, edges_count);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, entity_name.c_str(), data_size, w_str, data_size + 1);
HTREEITEM face_root = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, hBody);
pFrame->m_wndEntityView.m_wndEntityView.SetItemData(face_root, DWORD_PTR(faces[j]));
CreateEnitiyTreeFaceItems(face_root, faces[j]);
}
}
else
{
sprintf_s(str, "NonFACE");
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM non_root = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, hBody);
CreateEnitiyTreeFaceItems(non_root, entity_list[i]);
}
}
pFrame->m_wndEntityView.m_wndEntityView.SetCheck(hRoot);
CheckChild(&pFrame->m_wndEntityView.m_wndEntityView, hRoot, TRUE);
}
}
void CModelViewerView::CreateEnitiyTreeFaceItems(HTREEITEM& root, ENTITY* face)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
std::string entity_name;
if (pFrame)
{
auto get_tree_item_name = [](ENTITY* ent, const int ent_index, const int children_size)
{
std::string entity_name = "ENTITY";
if (is_BODY(ent))
{
entity_name = "BODY";
}
else if (is_FACE(ent))
{
entity_name = "FACE";
}
else if (is_EDGE(ent))
{
entity_name = "EDGE";
}
else if (is_VERTEX(ent))
{
entity_name = "VERTEX";
}
char str[255] = "\0";
std::string uid = find_attribute(ent, "uid");
if (strlen(uid.c_str()))
{
sprintf_s(str, "%s%03d %s(%d)", entity_name.c_str(), ent_index, uid.c_str(), children_size);
}
else
{
sprintf_s(str, "%s%03d(%d)", entity_name.c_str(), ent_index, children_size);
}
return std::string(str);
};
ENTITY_LIST edges;
api_get_edges(face, edges);
int edges_count = edges.count();
// edge子階層
for (int k = 0; k < edges_count; ++k)
{
EDGE* edge_edge = (EDGE*)edges[k];
ENTITY_LIST vertices;
api_get_vertices(edges[k], vertices);
int vertices_count = vertices.count();
entity_name = get_tree_item_name(edges[k], k, vertices_count);
int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, entity_name.c_str(), data_size, w_str, data_size + 1);
HTREEITEM edge_root = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, root);
pFrame->m_wndEntityView.m_wndEntityView.SetItemData(edge_root, DWORD_PTR(edges[k]));
CreateEnitiyTreeEdgeItems(edge_root, const_cast<const EDGE*&>(edge_edge));
}
}
}
void CModelViewerView::CreateEnitiyTreeEdgeItems(HTREEITEM& edge_root, const EDGE*& edge_edge)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
// 始点
SPAposition start_pos = edge_edge->start()->geometry()->coords();
sprintf_s(str, "Vertex(%6.3f, %6.3f, %6.3f)", start_pos.x(), start_pos.y(), start_pos.z());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM start_pos_root = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, edge_root);
pFrame->m_wndEntityView.m_wndEntityView.SetItemData(start_pos_root, DWORD_PTR(edge_edge->start()));
// 終点
SPAposition end_pos = edge_edge->end()->geometry()->coords();
sprintf_s(str, "Vertex(%6.3f, %6.3f, %6.3f)", end_pos.x(), end_pos.y(), end_pos.z());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM end_pos_root = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, edge_root);
pFrame->m_wndEntityView.m_wndEntityView.SetItemData(end_pos_root, DWORD_PTR(edge_edge->end()));
//// sense
//std::string sense = "FORWARD";
//if (edge_edge->sense() == FORWARD) // #define FORWARD FALSE
//{
// sense = "FORWARD";
//}
//else if (edge_edge->sense() == REVERSED)// #define REVERSED TRUE
//{
// sense = "REVERSED";
//}
//sprintf_s(str, "sense:%s", sense.c_str());
//MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
//auto tree_item = pFrame->m_wndEntityView.m_wndEntityView.InsertItem(w_str, 1, 1, edge_root);
}
}
void CModelViewerView::ReadWeldingResultRaw(const std::string str_welding_result, const std::string schema_file_path, bool is_export_edge)
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (!pFrame)
{
return;
}
CViewTreeAvro* avroTreeView = &pFrame->m_wndAvroView.m_wndAvroTreeView;
if (!avroTreeView)
{
return;
}
try
{
avro_fr::serialization::read_avro_datafile(str_welding_result, schema_file_path, m_welding_result_raw);
// メンバー変数セット
SetFeatures(m_welding_result_raw);
SetVirtualTopologies(m_welding_result_raw);
boost::filesystem::path welding_result(str_welding_result);
// tree生成
CreateViewTreeAvroItems(m_welding_result_raw, welding_result.filename().string());
// AVROからSATへの変換
if (is_export_edge)
{
std::string str_result;
size_t found = str_welding_result.find_last_of("/\\");
std::string welding_result_directory = str_welding_result.substr(0, found + 1);
ENTITY_LIST save_entity_list;
for (const auto& welding_edge : m_id_to_virtual_edges)
{
auto acis_edges = convert_welding_edge_to_acis_edge(welding_edge.second);
if (acis_edges)
{
ENTITY_LIST save_entity;
if (acis_edges.get().size() != 1)
{
continue;
}
auto acis_edge = acis_edges.get()[0];
std::string solid_id;
api_add_generic_named_attribute(acis_edge, "uid", welding_edge.first.c_str());
save_entity_list.add(acis_edge);
save_entity.add(acis_edge);
std::string save_topology_file_path = welding_result_directory + welding_edge.first + ".sat";
SaveSAT(save_topology_file_path.c_str(), &save_entity);
str_result += welding_edge.first + ".sat" + "\n";
}
}
std::string save_topology_file_path_total = (welding_result_directory + "welding_edge_to_acis_edge.sat");
SaveSAT(save_topology_file_path_total.c_str(), &save_entity_list);
//m_entity_list.add(save_entity_list);
str_result += "welding_edge_to_acis_edge.sat\n\n";
str_result += "OutputDirectory:" + welding_result_directory;
const unsigned int data_size = 1024 * 10;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
sprintf_s(str, "%s", str_result.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
AfxMessageBox(w_str);
}
}
catch (...)
{
AfxMessageBox(_T("Read avro file error!"));
}
}
void CModelViewerView::CreateViewTreeAvroItems(const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw, std::string file_name)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
pFrame->m_wndAvroView.m_wndAvroTreeView.DeleteAllItems();
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, file_name.c_str(), data_size, w_str, data_size + 1);
HTREEITEM avroRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 0, 0);
CreateViewTreeFeatures(avroRoot, welding_result_raw);
CreateViewTreeVirtualTopologies(avroRoot, welding_result_raw);
CreateViewAssemblyTree(avroRoot, welding_result_raw);
}
}
void CModelViewerView::SetFeatures(const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw)
{
// LineWeldingPartのマップ
for (const auto& feature : welding_result_raw.features)
{
std::string part_id = "";
if (avro_fr::union_util::is_same_type<fr::recognize_welding::SheetAssembly>(feature))
{
auto part = feature.get_SheetAssembly();
part_id = part.id;
m_id_to_sheet_assemblies.insert(std::make_pair(part_id, part));
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SideWelding>(feature))
{
auto part = feature.get_SideWelding();
part_id = part.id;
m_id_to_side_weldings.insert(std::make_pair(part_id, part));
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SurfaceWelding>(feature))
{
auto part = feature.get_SurfaceWelding();
part_id = part.id;
m_id_to_surface_weldings.insert(std::make_pair(part_id, part));
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::LineWeldingPart>(feature))
{
auto part = feature.get_LineWeldingPart();
part_id = part.id;
m_id_to_line_welding_parts.insert(std::make_pair(part_id, part));
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::NonWeldingPart>(feature))
{
auto part = feature.get_NonWeldingPart();
part_id = part.id;
m_id_to_non_welding_parts.insert(std::make_pair(part_id, part));
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SurfaceWeldingPart>(feature))
{
auto part = feature.get_SurfaceWeldingPart();
part_id = part.id;
m_id_to_suface_welding_parts.insert(std::make_pair(part_id, part));
}
m_id_to_features.insert(std::make_pair(part_id, feature));
}
}
void CModelViewerView::SetVirtualTopologies(const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw)
{
for (const auto& topology : welding_result_raw.virtualTopologies.faces)
{
m_id_to_virtual_faces.insert(std::make_pair(topology.id, &topology));
}
for (const auto& topology : welding_result_raw.virtualTopologies.loops)
{
m_id_to_virtual_loops.insert(std::make_pair(topology.id, &topology));
}
for (const auto& topology : welding_result_raw.virtualTopologies.coedges)
{
m_id_to_virtual_coedges.insert(std::make_pair(topology.id, &topology));
}
// 仮想edgeリスト取得し、マップにセット
for (const auto& edge : welding_result_raw.virtualTopologies.edges)
{
m_id_to_virtual_edges.insert(std::make_pair(edge.id, &edge));
}
// 仮想vertexリスト取得し、マップにセット
for (const auto& vertex : welding_result_raw.virtualTopologies.vertices)
{
m_id_to_virtual_vertices.insert(std::make_pair(vertex.id, &vertex));
}
}
void CModelViewerView::CreateViewTreeFeatures(HTREEITEM& avroTreeRoot, const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
int count_size = (int)welding_result_raw.features.size();
sprintf_s(str, "Features(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM featureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, avroTreeRoot);
for (int i = 0; i < count_size; ++i)
{
auto& feature = welding_result_raw.features[i];
if (avro_fr::union_util::is_same_type<fr::recognize_welding::SheetAssembly>(feature)) // SheetAssembly
{
auto part = feature.get_SheetAssembly();
sprintf_s(str, "SheetAssembly%03d %s", i,part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
// id
sprintf_s(str, "Id:%s", part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM idRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SideWelding>(feature)) // SideWelding
{
auto part = feature.get_SideWelding();
sprintf_s(str, "SideWelding%03d %s", i, part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
// id
sprintf_s(str, "Id:%s", part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM idRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// primaryFeature
sprintf_s(str, "primaryFeature:%s", part.primaryFeature.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM primaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// secondaryFeature
sprintf_s(str, "secondaryFeature:%s", part.secondaryFeature.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM secondaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// topPart
sprintf_s(str, "topPart:%s", part.topPart.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM topPartRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// bottomPart
sprintf_s(str, "bottomPart:%s", part.bottomPart.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM bottomPartRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SurfaceWelding>(feature)) // SurfaceWelding
{
auto part = feature.get_SurfaceWelding();
sprintf_s(str, "SurfaceWelding%03d %s", i, part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
// id
sprintf_s(str, "Id:%s", part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM idRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// primaryFeature
sprintf_s(str, "primaryFeature:%s", part.primaryFeature.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM primaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// secondaryFeature
sprintf_s(str, "secondaryFeature:%s", part.secondaryFeature.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM secondaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
// parts
int partsSize = (int)part.parts.size();
sprintf_s(str, "Parts(%d)", partsSize);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partsRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
for (int pi = 0; pi < partsSize; ++pi)
{
sprintf_s(str, "%s", part.parts.at(pi).c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partsRoot);
}
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::LineWeldingPart>(feature)) // LineWeldingPart
{
auto& part = feature.get_LineWeldingPart();
sprintf_s(str, "LineWeldingPart%03d %s", i, part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
CreateViewLineWeldingPart(partRoot, part);
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::SurfaceWeldingPart>(feature)) // SurfaceWeldingPart
{
auto part = feature.get_SurfaceWeldingPart();
sprintf_s(str, "SurfaceWeldingPart%03d %s", i, part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
// id
sprintf_s(str, "Id:%s", part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM idRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, partRoot);
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::NonWeldingPart>(feature)) // NonWeldingPart
{
auto part = feature.get_NonWeldingPart();
sprintf_s(str, "NonWeldingPart%03d %s", i, part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, featureRoot);
}
}
}
}
void CModelViewerView::CreateViewTreeVirtualTopologies(HTREEITEM& avroTreeRoot, const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
sprintf_s(str, "VirtualTopologies");
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM virtualTopologiesRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, avroTreeRoot);
// faces
//int count_size = (int)welding_result_raw.virtualTopologies.faces.size();
int count_size = (int)m_id_to_virtual_faces.size();
sprintf_s(str, "Faces(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM facesRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, virtualTopologiesRoot);
for (int ii = 0; ii < count_size; ++ii)
{
fr::recognize_welding::Face face = welding_result_raw.virtualTopologies.faces[ii];
sprintf_s(str, "Face%03d %s", ii, face.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM faceRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, facesRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(faceRoot, DWORD_PTR(&welding_result_raw.virtualTopologies.faces[ii].id));
CreateViewVirtualFace(faceRoot, face);
}
// loops
//count_size = (int)welding_result_raw.virtualTopologies.loops.size();
count_size = (int)m_id_to_virtual_loops.size();
sprintf_s(str, "Loops(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM loopsRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, virtualTopologiesRoot);
for (int ii = 0; ii < count_size; ++ii)
{
fr::recognize_welding::Loop loop = welding_result_raw.virtualTopologies.loops[ii];
sprintf_s(str, "Loop%03d %s", ii, loop.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM loopRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, loopsRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(loopRoot, DWORD_PTR(&welding_result_raw.virtualTopologies.loops[ii].id));
CreateViewVirtualLoop(loopRoot, loop);
}
// coedges
//count_size = (int)welding_result_raw.virtualTopologies.coedges.size();
count_size = (int)m_id_to_virtual_coedges.size();
sprintf_s(str, "Coedges(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM coedgesRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, virtualTopologiesRoot);
for (int ii = 0; ii < count_size; ++ii)
{
fr::recognize_welding::Coedge coedge = welding_result_raw.virtualTopologies.coedges[ii];
sprintf_s(str, "Coedge%03d %s", ii, coedge.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM coedgeRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, coedgesRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(coedgeRoot, DWORD_PTR(&welding_result_raw.virtualTopologies.coedges[ii].id));
CreateViewVirtualCoedge(coedgeRoot, coedge);
}
// edges
//count_size = (int)welding_result_raw.virtualTopologies.edges.size();
count_size = (int)m_id_to_virtual_edges.size();
sprintf_s(str, "Edges(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM edgesRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, virtualTopologiesRoot);
for (int ii = 0; ii < count_size; ++ii)
{
fr::recognize_welding::Edge edge = welding_result_raw.virtualTopologies.edges[ii];
std::string curve_type = "Edge";
// curve
auto curve = edge.curve;
if (avro_fr::union_util::is_same_type<fr::recognize_welding::Straight>(curve))
{
curve_type = "Straight";
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::Polyline>(curve))
{
curve_type = "Polyline";
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::Ellipse>(curve))
{
curve_type = "Ellipse";
}
else if (avro_fr::union_util::is_same_type<fr::recognize_welding::Circle>(curve))
{
curve_type = "Circle";
}
sprintf_s(str, "%s%03d %s", curve_type.c_str(), ii, edge.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM edgeRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, edgesRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(edgeRoot, DWORD_PTR(&welding_result_raw.virtualTopologies.edges[ii].id));
CreateViewVirtualEdge(edgeRoot, edge);
}
// vertices
//count_size = (int)welding_result_raw.virtualTopologies.vertices.size();
count_size = (int)m_id_to_virtual_vertices.size();
sprintf_s(str, "Vertices(%d)", count_size);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM verticesRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, virtualTopologiesRoot);
for (int ii = 0; ii < count_size; ++ii)
{
fr::recognize_welding::Vertex vertex = welding_result_raw.virtualTopologies.vertices[ii];
sprintf_s(str, "Vertex%03d %s", ii, vertex.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM vertexRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, verticesRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(vertexRoot, DWORD_PTR(&welding_result_raw.virtualTopologies.vertices[ii].id));
CreateViewVirtualVertex(vertexRoot, vertex);
}
}
}
void CModelViewerView::CreateViewAssemblyTree(HTREEITEM& avroTreeRoot, const fr::recognize_welding::RecognizedWeldingResultRaw& welding_result_raw)
{
const unsigned int data_size = 255;
wchar_t w_str[data_size + 1] = { 0x00 };
char str[data_size] = "\0";
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if (pFrame)
{
int count_size = 0;
int i = 0;
for (auto sheet_assembly : m_id_to_sheet_assemblies)
{
sprintf_s(str, "SheetAssembly %s", sheet_assembly.second.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM sheetAssemblyRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, avroTreeRoot);
for (auto& welding_id : sheet_assembly.second.weldings)
{
auto side_welding_find_id = m_id_to_side_weldings.find(welding_id);
if (side_welding_find_id != m_id_to_side_weldings.end())
{
auto& welding = side_welding_find_id->second;
sprintf_s(str, "SideWelding %s", welding.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM weldingRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, sheetAssemblyRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(weldingRoot, DWORD_PTR(&welding.id));
auto& primary_feature_id = welding.primaryFeature;
sprintf_s(str, "PrimaryFeature %s", primary_feature_id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM primaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, weldingRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(primaryFeatureRoot, DWORD_PTR(&primary_feature_id));
auto& secondary_feature_id = welding.secondaryFeature;
sprintf_s(str, "SecondaryFeature %s", secondary_feature_id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM secondaryFeatureRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, weldingRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(secondaryFeatureRoot, DWORD_PTR(&secondary_feature_id));
sprintf_s(str, "TopPart %s", welding.topPart.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM topPartRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, weldingRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(topPartRoot, DWORD_PTR(&welding.topPart));
auto find_it = m_id_to_line_welding_parts.find(welding.topPart);
if (find_it != m_id_to_line_welding_parts.end())
{
auto& part = find_it->second;
sprintf_s(str, "LineWeldingPart %s", part.id.c_str());
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, data_size, w_str, data_size + 1);
HTREEITEM partRoot = pFrame->m_wndAvroView.m_wndAvroTreeView.InsertItem(w_str, 1, 1, topPartRoot);
pFrame->m_wndAvroView.m_wndAvroTreeView.SetItemData(partRoot, DWORD_PTR(&part.id));
CreateViewLineWeldingPart(partRoot, find_it->second);
}
else
{