This repository has been archived by the owner on Apr 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
designer2d_cloth.cpp
1609 lines (1527 loc) · 63.5 KB
/
designer2d_cloth.cpp
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
/*
* design2d_cloth.cpp
* sensitive couture
*
* Created by Nobuyuki Umetani on 9/14/10.
* Copyright 2010 The University of Tokyo and Columbia University. All rights reserved.
*
*/
#if defined(__VISUALC__)
#pragma warning ( disable : 4996 )
#pragma warning ( disable : 4786 )
#endif
#include "delfem/serialize.h"
#include "designer2d_cloth.h"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void CDesigner2D_Cloth::DrawSelection()
{
pDrawerCAD->DrawSelection(0);
}
Com::CBoundingBox3D CDesigner2D_Cloth::GetBoundingBox(double rot[]) const
{
//return pDrawerCAD->GetBoundingBox(rot);
// cad_2d.Get
const std::vector<unsigned int>& aIdE =cad_2d.GetAryElemID(Cad::EDGE);
Com::CBoundingBox2D bb2d;
for(unsigned int iide=0;iide<aIdE.size();iide++){
unsigned int id_e = aIdE[iide];
const Cad::CEdge2D& e = cad_2d.GetEdge(id_e);
bb2d += e.GetBoundingBox();
}
return Com::CBoundingBox3D(bb2d.x_min,bb2d.x_max, bb2d.y_min,bb2d.y_max,-1,1);
}
void CDesigner2D_Cloth::SetTextureScale_CadFace(double tex_scale)
{
this->tex_scale = tex_scale;
this->InitDrawer();
}
void CDesigner2D_Cloth::SetColor_CadFace(double r, double g, double b)
{
face_color[0] = r;
face_color[1] = g;
face_color[2] = b;
const std::vector<unsigned int>& aIdL = cad_2d.GetAryElemID(Cad::LOOP);
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
cad_2d.SetColor_Loop(id_l,face_color);
}
this->InitDrawer();
}
void CDesigner2D_Cloth::SetTextureCenter_FaceCAD(double cx, double cy)
{
// std::cout << cx << " " << cy << std::endl;
if( pDrawerCAD == 0 ) return;
pDrawerCAD->SetTexCenter(cx, cy);
}
void CDesigner2D_Cloth::FollowMshToCad_ifNeeded()
{
if( setIdVCad_NeedFollow.empty() ){ return; }
// std::cout << "FollowMshToCad_ifNeeded()" << std::endl;
std::vector<unsigned int> aIdV_del;
std::set<unsigned int>::iterator itr = setIdVCad_NeedFollow.begin();
for(;itr!=setIdVCad_NeedFollow.end();itr++){
const unsigned int id_v = *itr;
// std::cout << "follow " << id_v << std::endl;
if( !cad_2d.IsElemID(Cad::VERTEX,id_v) ) continue;
unsigned int itype_ope = 0;
if( mesh_2d.FitMeshToCad_Vertex(cad_2d, id_v, itype_ope) ){ aIdV_del.push_back(id_v); }
if( itype_ope == 0 ){
std::cout << "fail folow mesh to cad rebuild mesh" << std::endl;
this->Solve_fromCad_InterpValue();
this->Msh_PrecompDrag(itype_cad_elem_prec, id_cad_elem_prec);
is_updated_coord = false;
is_updated_edge = false;
setIdVCad_NeedFollow.clear();
return;
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
}
for(unsigned int iid_v=0;iid_v<aIdV_del.size();iid_v++){
setIdVCad_NeedFollow.erase( aIdV_del[iid_v] );
}
}
void CDesigner2D_Cloth::SetSelection(const std::vector<Com::View::SSelectedObject>& aSelecObj)
{
pDrawerCAD->ClearSelected();
m_id_cad_part = 0; m_itype_cad_part = Cad::NOT_SET;
if( aSelecObj.size() == 0 ) return;
pDrawerCAD->GetCadPartID(aSelecObj[0].name,m_itype_cad_part,m_id_cad_part);
pDrawerCAD->AddSelected( aSelecObj[0].name );
m_picked_x = aSelecObj[0].picked_pos.x;
m_picked_y = aSelecObj[0].picked_pos.y;
}
void CDesigner2D_Cloth::Cad_GetPicked
(Cad::CAD_ELEM_TYPE& itype, unsigned int& id,
double& x, double& y) const
{
id = m_id_cad_part;
itype = m_itype_cad_part;
x = m_picked_x;
y = m_picked_y;
}
bool CDesigner2D_Cloth::Cad_Move
(Cad::CAD_ELEM_TYPE itype_cad_part, unsigned int id_cad_part,
const Com::CVector2D& pos_pre, const Com::CVector2D& pos_cur, double tor)
{
if( !cad_2d.IsElemID(itype_cad_part,id_cad_part) ){ return false; }
if( pAnalysis != 0 ){
pAnalysis->Update_Boundary_Condition_Cad_Move(itype_cad_part,id_cad_part,
pos_cur.x-pos_pre.x, pos_cur.y-pos_pre.y,
slider_deform);
}
unsigned int itype_ope = 0;
if( itype_cad_part == Cad::VERTEX ){
if( !this->MoveVertex(id_cad_part,pos_cur) ){ return false; }
is_updated_cad = true;
// if( mesh_2d.GetElemID_FromCadID(id_cad_part,Cad::VERTEX ) == 0 ) return true;
// if this vertex doesn't touch any loop that have mesh, we don't have to move mesh and sensitivity
if( itype_cad_elem_prec!=Cad::VERTEX || id_cad_elem_prec!=id_cad_part){ this->Msh_PrecompDrag(Cad::VERTEX, id_cad_part); }
if( !mesh_2d.FitMeshToCad_UsingPrecomp(cad_2d, Cad::VERTEX,id_cad_part, itype_ope) ){ goto FAIL_FIT_MESH; }
}
if( itype_cad_part == Cad::EDGE ){
if( !this->MoveEdge(id_cad_part, pos_cur-pos_pre) ){ return false; }
is_updated_cad = true;
// if( mesh_2d.GetElemID_FromCadID(id_cad_part,Cad::EDGE ) == 0 ) return true;
// if this edge doesn't touch any loop that have mesh, we don't have to move mesh and sensitivity
if( itype_cad_elem_prec!=Cad::EDGE || id_cad_elem_prec!=id_cad_part){ this->Msh_PrecompDrag(Cad::EDGE, id_cad_part); }
if( !mesh_2d.FitMeshToCad_UsingPrecomp(cad_2d, Cad::EDGE,id_cad_part, itype_ope) ){ goto FAIL_FIT_MESH; }
}
if( itype_cad_part == Cad::LOOP ){
if( !this->MoveLoop(id_cad_part,pos_cur-pos_pre) ){ return false; }
is_updated_cad = true;
if( itype_cad_elem_prec!=Cad::LOOP || id_cad_elem_prec!=id_cad_part){ this->Msh_PrecompDrag(Cad::LOOP, id_cad_part); }
if( !mesh_2d.FitMeshToCad_UsingPrecomp(cad_2d, Cad::LOOP,id_cad_part, itype_ope) ){ goto FAIL_FIT_MESH; }
}
is_updated_coord = is_updated_coord || (itype_ope&1);
is_updated_edge = is_updated_edge || (itype_ope&2);
return true;
FAIL_FIT_MESH:
this->Solve_fromCad_InterpValue();
this->Msh_PrecompDrag(itype_cad_part, id_cad_part);
is_updated_coord = false;
is_updated_edge = false;
is_updated_cad = false;
// return true;
// for(unsigned int i=0;i<1;i++){ this->Solve_ifNeeded(); }
if(pAnalysis != 0 ){
/*
if( pAnalysis->GetMode() != CLOTH_INITIAL_LOCATION ){
std::vector<double> har;
this->Msh_GetHarmonicPrecomp(har); // Get mesh harmonic function
if( har.size() == 0 ) return true;
pAnalysis->SetSensitivity(itype_cad_part,id_cad_part,har,pos_cur.x,pos_cur.y);
}
*/
}
return true;
// */
}
////////////////////////////////////////////////////////////////
// à ëäïœâª
bool CDesigner2D_Cloth::Cad_Remove(Cad::CAD_ELEM_TYPE itype, unsigned int id)
{
if( itype == Cad::LOOP ){
if( mesh_2d.IsIdLCad_CutMesh(id) ) return false;
std::vector<unsigned int> aIdE, aIdV;
for(Cad::CBRepSurface::CItrLoop pItr = cad_2d.GetItrLoop(id);!pItr.IsEnd();pItr++){
unsigned int id_e; bool is_same_dir;
pItr.GetIdEdge(id_e,is_same_dir);
aIdE.push_back(id_e);
aIdV.push_back(pItr.GetIdVertex());
}
for(unsigned int iie=0;iie<aIdE.size();iie++){
cad_2d.RemoveElement(Cad::EDGE,aIdE[iie]);
}
for(unsigned int iiv=0;iiv<aIdV.size();iiv++){
cad_2d.RemoveElement(Cad::VERTEX,aIdV[iiv]);
}
}
if( itype == Cad::VERTEX ){
if( !cad_2d.RemoveElement(itype,id) ){ return false; }
}
if( itype == Cad::EDGE ){
unsigned int id_l_l, id_l_r;
cad_2d.GetIdLoop_Edge(id_l_l,id_l_r, id);
const bool is_l_l_cut = mesh_2d.IsIdLCad_CutMesh(id_l_l);
const bool is_l_r_cut = mesh_2d.IsIdLCad_CutMesh(id_l_r);
if( !cad_2d.RemoveElement(itype,id) ) return false;
if( is_l_l_cut != is_l_r_cut ){ // àÍï˚Ç™ÉÅÉbÉVÉÖÇ™Ç ÇËÅCàÍï˚Ç…ÉÅÉbÉVÉÖǙǻǢèÍçáÇÕÅCÇ≈Ç´ÇÈÇæÇØÉÅÉbÉVÉÖÇçÏÇÈ
if( cad_2d.IsElemID(Cad::LOOP,id_l_l) ){ mesh_2d.AddIdLCad_CutMesh(id_l_l); }
if( cad_2d.IsElemID(Cad::LOOP,id_l_r) ){ mesh_2d.AddIdLCad_CutMesh(id_l_r); }
}
// ÉÅÉbÉVÉÖÇêÿÇÈÉãÅ[ÉvÇ™ë∂ç›ÇµÇ»ÇØÇÍÇŒè¡Ç∑
const std::vector<unsigned int>& aIdL = mesh_2d.GetIdLCad_CutMesh();
for(unsigned int iil=0;iil<aIdL.size();iil++){
unsigned int id_l = aIdL[iil];
if( cad_2d.IsElemID(Cad::LOOP,id_l) ){ continue; }
mesh_2d.RemoveIdLCad_CutMesh(id_l);
break; // DZDZÇ≈breakǵǻǢÇ∆ÉGÉâÅ[Ç…Ç»ÇÈ
}
}
this->Solve_fromCad_InterpValue();
return true;
}
bool CDesigner2D_Cloth::Cad_SetCurveType(unsigned int id_e, unsigned int itype )
{
// std::cout << "CGuiListner_Analysis2D_Interactive::Cad_SetCurveType" << std::endl;
if( !cad_2d.IsElemID(Cad::EDGE,id_e) ) return false;
if( itype == 0 ){ is_updated_cad = cad_2d.SetCurve_Line(id_e); }
else if( itype == 1 ){ is_updated_cad = cad_2d.SetCurve_Arc( id_e); }
else if( itype == 2 ){ is_updated_cad = cad_2d.SetCurve_Polyline(id_e); }
if( !is_updated_cad ) return false;
////////////////
if( m_is_solve_cad_change ){ // ÉÅÉbÉVÉÖÇìÆÇ©Ç∑
unsigned int itype_ope;
if( !mesh_2d.FitMeshToCad_Edge(cad_2d,id_e, itype_ope) ){
unsigned int id_vs, id_ve;
cad_2d.GetIdVertex_Edge(id_vs,id_ve,id_e);
setIdVCad_NeedFollow.insert( id_vs );
setIdVCad_NeedFollow.insert( id_ve );
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
}
return true;
}
bool CDesigner2D_Cloth::Cad_DragArc(unsigned int id_e, const Com::CVector2D& pos_obj)
{
if( !cad_2d.IsElemID(Cad::EDGE,id_e) ) return false;
if( cad_2d.GetEdgeCurveType(id_e) != 1 ) return true;
if( !cad_2d.DragArc(id_e,pos_obj) ) return false;
is_updated_cad = true;
if( m_is_solve_cad_change ){
unsigned int itype_ope;
if( !mesh_2d.FitMeshToCad_Edge(cad_2d,id_e, itype_ope) ){
unsigned int id_vs, id_ve;
cad_2d.GetIdVertex_Edge(id_vs,id_ve,id_e);
setIdVCad_NeedFollow.insert( id_vs );
setIdVCad_NeedFollow.insert( id_ve );
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
is_updated_cad = true;
}
return true;
}
bool CDesigner2D_Cloth::Cad_DragPolyline(unsigned int id_e, const Com::CVector2D& dist)
{
if( !cad_2d.IsElemID(Cad::EDGE,id_e) ) return false;
if( cad_2d.GetEdgeCurveType(id_e) != 2 ) return true;
if( !cad_2d.DragPolyline(id_e,dist) ) return false;
std::cout << "Cad_DragPolyline" << std::endl;
is_updated_cad = true;
if( m_is_solve_cad_change ){
unsigned int itype_ope;
if( !mesh_2d.FitMeshToCad_Edge(cad_2d,id_e, itype_ope) ){
this->Solve_fromCad_InterpValue();
is_updated_coord = false;
is_updated_edge = false;
is_updated_cad = false;
return true;
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
is_updated_cad = true;
}
return true;
}
bool CDesigner2D_Cloth::Cad_PreCompDragPolyline(unsigned int id_e, const Com::CVector2D& pick_pos)
{
if( !cad_2d.IsElemID(Cad::EDGE,id_e) ) return false;
if( cad_2d.GetEdgeCurveType(id_e) != 2 ) return true;
if( !cad_2d.PreCompDragPolyline(id_e,pick_pos) ) return false;
is_updated_cad = true;
itype_cad_elem_prec = Cad::NOT_SET;
id_cad_elem_prec = 0;
isnt_mesh_deform_sensitivity = true;
if( m_is_solve_cad_change ){
unsigned int itype_ope;
if( !mesh_2d.FitMeshToCad_Edge(cad_2d,id_e, itype_ope) ){
unsigned int id_vs, id_ve;
cad_2d.GetIdVertex_Edge(id_vs,id_ve,id_e);
setIdVCad_NeedFollow.insert( id_vs );
setIdVCad_NeedFollow.insert( id_ve );
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
is_updated_cad = true;
}
return true;
}
// smoothing edge (id_e) if radius is negative smooth whole edge
bool CDesigner2D_Cloth::Cad_SmoothingPolylineEdge(unsigned int id_e, unsigned int niter,
const Com::CVector2D& pos, double radius)
{
if( !cad_2d.IsElemID(Cad::EDGE,id_e) ) return false;
if( cad_2d.GetEdgeCurveType(id_e) != 2 ) return true;
if( !cad_2d.SmoothingPolylineEdge(id_e,niter,pos,radius) ) return false;
is_updated_cad = true;
if( m_is_solve_cad_change ){
unsigned int itype_ope;
if( !mesh_2d.FitMeshToCad_Edge(cad_2d,id_e, itype_ope) ){
unsigned int id_vs, id_ve;
cad_2d.GetIdVertex_Edge(id_vs,id_ve,id_e);
setIdVCad_NeedFollow.insert( id_vs );
setIdVCad_NeedFollow.insert( id_ve );
}
is_updated_coord = is_updated_coord || (itype_ope&1); // êflì_ÇÃà⁄ìÆ
is_updated_edge = is_updated_edge || (itype_ope&2); // óvëfÇÃêÿÇËë÷Ƕ
is_updated_cad = true;
}
return true;
}
void CDesigner2D_Cloth::Draw(unsigned int idraw_object)
{
if( this->is_updated_cad ){
this->is_updated_cad = false;
pDrawerCAD->UpdateCAD_TopologyGeometry(cad_2d);
}
if( idraw_object == 0 ){ // analysis and cad_rigid_loop, cad_edge and cad_vertex
if( pAnalysis != 0 ){
pAnalysis->UpdateAnimationDrawer();
pAnalysis->Draw();
}
else{
pDrawerMsh->Draw();
}
////////////////
{
const std::vector<unsigned int>& aIdL = this->cad_2d.GetAryElemID(Cad::LOOP);
for(unsigned int i=0;i<aIdL.size();i++){
const unsigned int id_l = aIdL[i];
if( pAnalysis != 0 ){ pDrawerCAD->SetIsShow(false,Cad::LOOP,id_l); }
else{ pDrawerCAD->SetIsShow(true,Cad::LOOP,id_l); }
}
}
{
const std::vector<unsigned int>& aIdL = mesh_2d.GetIdLCad_CutMesh();
for(unsigned int iil=0;iil<aIdL.size();iil++){
const unsigned int id_l = aIdL[iil];
pDrawerCAD->SetIsShow(false,Cad::LOOP,id_l);
}
}
pDrawerCAD->Draw();
}
else if( idraw_object == 1 ){ // cad
pDrawerCAD->SetIsShow(false,Cad::LOOP, this->cad_2d.GetAryElemID(Cad::LOOP) );
const std::vector<unsigned int>& aIdL = mesh_2d.GetIdLCad_CutMesh();
for(unsigned int iil=0;iil<aIdL.size();iil++){
const unsigned int id_l = aIdL[iil];
pDrawerCAD->SetIsShow(true,Cad::LOOP,id_l);
}
pDrawerCAD->Draw();
}
else if( idraw_object == 2 ){ // mesh
pDrawerMsh->Draw();
}
else if( idraw_object == 3 ){ // mesh and cad edge & vertex
pDrawerMsh->Draw();
pDrawerCAD->SetIsShow(false,Cad::LOOP, this->cad_2d.GetAryElemID(Cad::LOOP) );
/*
pDrawerCAD->SetIsShow(true,Cad::LOOP, this->cad_2d.GetAryElemID(Cad::LOOP) );
const std::vector<unsigned int>& aIdL = mesh_2d.GetIdLCad_CutMesh();
for(unsigned int iil=0;iil<aIdL.size();iil++){
const unsigned int id_l = aIdL[iil];
pDrawerCAD->SetIsShow(false,Cad::LOOP,id_l);
}
*/
pDrawerCAD->Draw();
}
else if( idraw_object == 4 ){
if( pAnalysis != 0 ){
pAnalysis->UpdateAnimationDrawer();
pAnalysis->Draw();
}
}
else if( idraw_object == 5 ){
if( pAnalysis != 0 ){ pAnalysis->DrawBoundaryCondition(cad_2d); }
}
}
void CDesigner2D_Cloth::InitDrawer()
{
// std::cout << "Init Drawer Cloth Designer" << std::endl;
double tex_cent_x=0, tex_cent_y=0;
if( pDrawerCAD != 0 ){
pDrawerCAD->GetTexCenter(tex_cent_x, tex_cent_y);
delete pDrawerCAD;
}
pDrawerCAD = new Cad::View::CDrawer_Cad2D(cad_2d);
pDrawerCAD->EnableUVMap(true);
pDrawerCAD->SetAntiAliasing(true);
pDrawerCAD->SetTextureScale(tex_scale);
pDrawerCAD->SetTexCenter(tex_cent_x,tex_cent_y);
if( pDrawerMsh != 0 ){ delete pDrawerMsh; }
pDrawerMsh = new Msh::View::CDrawerMsh2D(mesh_2d);
// if( pAnalysis != 0 ){ pAnalysis->InitDrawer(); }
}
void CDesigner2D_Cloth::SetAnalysisInitialize(CAnalysis2D_Cloth_Static* pAnalysis,unsigned int iprob)
{
this->setIdVCad_NeedFollow.clear();
this->pAnalysis = pAnalysis;
if( pAnalysis != 0 ){
pAnalysis->SetModelProblem_Cloth(cad_2d,mesh_2d,iprob,slider_deform,aSymIdVPair);
}
else{
aSymIdVPair.clear();
if( iprob == 0 ){
unsigned int id_l0;
{ // Make model
cad_2d.Clear();
std::vector<Com::CVector2D> vec_ary;
vec_ary.push_back( Com::CVector2D(0.0,0.0) );
vec_ary.push_back( Com::CVector2D(1.0,0.0) );
vec_ary.push_back( Com::CVector2D(1.0,1.0) );
vec_ary.push_back( Com::CVector2D(0.0,1.0) );
id_l0 = cad_2d.AddPolygon( vec_ary ).id_l_add;
}
{ // ÉÅÉbÉVÉÖÇÃê›íË
mesh_2d.Clear();
mesh_2d.AddIdLCad_CutMesh(id_l0);
mesh_2d.SetMeshingMode_ElemSize(2000);
mesh_2d.Meshing(cad_2d);
}
}
else if( iprob == 1 ){
unsigned int id_l0;
{ // Make model
cad_2d.Clear();
std::vector<Com::CVector2D> vec_ary;
vec_ary.push_back( Com::CVector2D(+0.00,0.00) ); // 0
vec_ary.push_back( Com::CVector2D(+1.00,0.00) ); // 1
vec_ary.push_back( Com::CVector2D(+1.00,1.00) ); // 2
vec_ary.push_back( Com::CVector2D(+1.35,0.83) ); // 3
vec_ary.push_back( Com::CVector2D(+1.50,1.2) ); // 4
vec_ary.push_back( Com::CVector2D(+0.80,1.5) ); // 5
////
vec_ary.push_back( Com::CVector2D(+0.20,1.50) ); // 6
vec_ary.push_back( Com::CVector2D(-0.50,1.20) ); // 7
vec_ary.push_back( Com::CVector2D(-0.35,0.83) ); // 8
vec_ary.push_back( Com::CVector2D(+0.00,1.00) ); // 9
Cad::CCadObj2D::CResAddPolygon res = cad_2d.AddPolygon( vec_ary );
id_l0 = res.id_l_add;
cad_2d.SetCurve_Polyline(res.aIdE[5]);
cad_2d.PreCompDragPolyline(res.aIdE[5],vec_ary[5]*0.5+vec_ary[6]*0.5);
cad_2d.DragPolyline(res.aIdE[5],vec_ary[5]*0.5+vec_ary[6]*0.5+Com::CVector2D(-0.0,-0.08));
////
aSymIdVPair.push_back( std::make_pair(res.aIdV[1],res.aIdV[0]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[2],res.aIdV[9]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[3],res.aIdV[8]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[4],res.aIdV[7]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[5],res.aIdV[6]) );
}
{ // ÉÅÉbÉVÉÖÇÃê›íË
mesh_2d.Clear();
mesh_2d.AddIdLCad_CutMesh(id_l0);
mesh_2d.SetMeshingMode_ElemSize(4000);
mesh_2d.Meshing(cad_2d);
}
}
else if( iprob == 2 ){
unsigned int id_l0;
{ // Make model
cad_2d.Clear();
std::vector<Com::CVector2D> vec_ary;
vec_ary.push_back( Com::CVector2D(+0.00,0.00) ); // 0
vec_ary.push_back( Com::CVector2D(+1.00,0.00) ); // 1
vec_ary.push_back( Com::CVector2D(+1.00,1.00) ); // 2
// vec_ary.push_back( Com::CVector2D(+0.90,1.10) );
vec_ary.push_back( Com::CVector2D(+0.90,1.50) ); // 3
vec_ary.push_back( Com::CVector2D(+0.80,1.50) ); // 4
////
vec_ary.push_back( Com::CVector2D(+0.20,1.50) ); // 5
vec_ary.push_back( Com::CVector2D(+0.10,1.50) ); // 6
// vec_ary.push_back( Com::CVector2D(+0.10,1.10) );
vec_ary.push_back( Com::CVector2D(+0.00,1.00) ); // 7
Cad::CCadObj2D::CResAddPolygon res = cad_2d.AddPolygon( vec_ary );
id_l0 = res.id_l_add;
cad_2d.SetCurve_Polyline(res.aIdE[4]);
cad_2d.PreCompDragPolyline(res.aIdE[4],vec_ary[4]*0.5+vec_ary[5]*0.5);
cad_2d.DragPolyline(res.aIdE[4],vec_ary[4]*0.5+vec_ary[5]*0.5+Com::CVector2D(-0.0,-0.08));
////
aSymIdVPair.push_back( std::make_pair(res.aIdV[1],res.aIdV[0]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[2],res.aIdV[7]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[3],res.aIdV[6]) );
aSymIdVPair.push_back( std::make_pair(res.aIdV[4],res.aIdV[5]) );
}
{ // ÉÅÉbÉVÉÖÇÃê›íË
mesh_2d.Clear();
mesh_2d.AddIdLCad_CutMesh(id_l0);
mesh_2d.SetMeshingMode_ElemSize(1000);
mesh_2d.Meshing(cad_2d);
}
Cad_AddCutLine(Com::CVector2D(0.5,1), Com::CVector2D(0.5,0.2));
}
}
this->InitDrawer();
/*
if( pDrawerCAD != 0 ){ delete pDrawerCAD; }
pDrawerCAD = new Cad::View::CDrawer_Cad2D(cad_2d);
if( pDrawerMsh != 0 ){ delete pDrawerMsh; }
pDrawerMsh = new Msh::View::CDrawerMsh2D(mesh_2d);
*/
}
void CDesigner2D_Cloth::SetAnalysis(CAnalysis2D_Cloth_Static* pAnalysis){
this->pAnalysis = pAnalysis;
this->InitDrawer();
/*
if( pDrawerCAD != 0 ){ delete pDrawerCAD; }
pDrawerCAD = new Cad::View::CDrawer_Cad2D(cad_2d);
if( pDrawerMsh != 0 ){ delete pDrawerMsh; }
pDrawerMsh = new Msh::View::CDrawerMsh2D(mesh_2d);
*/
}
void CDesigner2D_Cloth::Solve_fromCad_InitValue()
{
mesh_2d.Meshing(cad_2d);
if( pAnalysis != 0 ){ pAnalysis->BuildFEM_ClearValueField(cad_2d,mesh_2d); }
this->InitDrawer();
}
void CDesigner2D_Cloth::Solve_fromCad_InterpValue(const std::vector< std::pair<unsigned int,unsigned int> >& aNewL)
{
mesh_2d.Meshing(cad_2d);
if( pAnalysis != 0 ){ pAnalysis->BuildFEM_InterpValueField(cad_2d,mesh_2d,aNewL); }
this->InitDrawer();
}
void CDesigner2D_Cloth::Solve_ifNeeded(){
/*
{ // bulding mesh for each computation
mesh_2d.Meshing(cad_2d);
if( pAnalysis != 0 ){ pAnalysis->SolveInitial(cad_2d,mesh_2d); }
this->is_updated_cad = false;
this->is_updated_coord = false;
this->is_updated_edge = false;
if( pDrawerMsh != 0 ){ delete pDrawerMsh; }
pDrawerMsh = new Msh::View::CDrawerMsh2D(mesh_2d);
return;
}
*/
if( is_updated_cad && !(is_updated_coord||is_updated_edge) ){
std::cout << "fail mesh update" << std::endl;
mesh_2d.Meshing(cad_2d);
const std::vector< std::pair<unsigned int,unsigned int> > aNewL;
if( pAnalysis != 0 ){ pAnalysis->BuildFEM_InterpValueField(cad_2d,mesh_2d,aNewL); }
// if( pAnalysis != 0 ){ pAnalysis->BuildFEM_ClearValueField(cad_2d,mesh_2d); }
this->InitDrawer();
is_updated_cad = false;
is_updated_coord = false;
is_updated_edge = false;
this->Msh_PrecompDrag(itype_cad_elem_prec, id_cad_elem_prec);
return;
}
if( is_updated_coord || is_updated_edge ){
if( pDrawerMsh != 0 ){ delete pDrawerMsh; }
pDrawerMsh = new Msh::View::CDrawerMsh2D(mesh_2d);
}
// if( !m_is_solve_cad_change ){ return; }
if( pAnalysis == 0 ) return;
SOLVER_FLAG solver_flg = this->pAnalysis->UpdateMeshAndSolve(mesh_2d,
is_updated_coord,is_updated_edge,
m_is_solve_cad_change,isnt_mesh_deform_sensitivity);
if( solver_flg != SUCCESS ){
mesh_2d.Meshing(cad_2d);
const std::vector< std::pair<unsigned int,unsigned int> > aNewL;
this->pAnalysis->BuildFEM_InterpValueField(cad_2d,mesh_2d,aNewL);
}
is_updated_coord = false;
is_updated_edge = false;
}
void CDesigner2D_Cloth::Serialize( Com::CSerializer& arch )
{
// if( !arch.IsOpen() ) return;
if( arch.IsLoading() ){
const unsigned int buff_size = 256;
char class_name[buff_size];
arch.ReadDepthClassName(class_name,buff_size);
std::cout << class_name << std::endl;
assert( strncmp(class_name,"CGuiListner_Analysis2D_Interactive",34) == 0 );
arch.ShiftDepth(true);
cad_2d.Serialize(arch);
mesh_2d.Serialize(arch,true);
arch.ShiftDepth(false);
mesh_2d.Meshing(cad_2d);
}
else{
arch.WriteDepthClassName("CGuiListner_Analysis2D_Interactive");
arch.ShiftDepth(true);
cad_2d.Serialize(arch);
mesh_2d.Serialize(arch,true);
arch.ShiftDepth(false);
}
}
unsigned int CDesigner2D_Cloth::AddDartDiamond
(unsigned int id_l,const Com::CVector2D& pos, const Com::CVector2D& poe)
{
if( !mesh_2d.IsIdLCad_CutMesh(id_l) ) return 0;
Com::CVector2D ve(-(pos-poe).y,(pos-poe).x);
ve.Normalize();
ve *= 0.025;
Com::CVector2D c = (pos+poe)*0.5;
Com::CVector2D po1 = c+ve;
Com::CVector2D po2 = c-ve;
if( !cad_2d.CheckIsPointInsideLoop(id_l,po1) ) return 0;
if( !cad_2d.CheckIsPointInsideLoop(id_l,po2) ) return 0;
std::vector< Com::CVector2D > aVec;
aVec.push_back(pos);
aVec.push_back(po1);
aVec.push_back(poe);
aVec.push_back(po2);
// const unsigned int id_l_add = cad_2d.AddPolygon(aVec,id_l).id_l_add;
const Cad::CCadObj2D::CResAddPolygon& res = cad_2d.AddPolygon(aVec,id_l);
const unsigned int id_l_add = res.id_l_add;
if( id_l_add == 0 ){ return 0; }
CDartDiamond dart;
{
dart.id_l = res.id_l_add;
dart.id_vu = res.aIdV[0];
dart.id_vl = res.aIdV[1];
dart.id_vd = res.aIdV[2];
dart.id_vr = res.aIdV[3];
dart.id_e_ul = res.aIdE[0];
dart.id_e_ld = res.aIdE[1];
dart.id_e_dr = res.aIdE[2];
dart.id_e_ru = res.aIdE[3];
}
aDartDiamond.push_back(dart);
Solve_fromCad_InterpValue();
this->InitDrawer();
if( pAnalysis != 0 ){
pAnalysis->PerformStaticSolver();
pAnalysis->ConnectEdge(this->cad_2d,this->mesh_2d,res.aIdE[0],res.aIdE[3]);
pAnalysis->ConnectEdge(this->cad_2d,this->mesh_2d,res.aIdE[1],res.aIdE[2]);
}
return id_l_add;
}
unsigned int CDesigner2D_Cloth::AddDartEdge
(unsigned int id_l, unsigned int id_e0, bool is_same_dir0,
const Com::CVector2D& pos, const Com::CVector2D& p_nearest)
{
if( !cad_2d.IsElemID(Cad::EDGE,id_e0) ) return 0;
if( cad_2d.GetEdgeCurveType(id_e0) != 0 ) return 0;
Com::CVector2D out0,out1;
double ratio0, ratio1;
{
const Cad::CEdge2D& edge = cad_2d.GetEdge(id_e0);
bool is_exceed0, is_exceed1;
edge.GetPointOnCurve_OnCircle(p_nearest, 0.025, true, is_exceed0, out0);
edge.GetPointOnCurve_OnCircle(p_nearest, 0.025,false, is_exceed1, out1);
if( is_exceed0 ) return 0;
if( is_exceed1 ) return 0;
ratio0 = Com::Distance(p_nearest,edge.po_s);
ratio1 = Com::Distance(p_nearest,edge.po_e);
const double invsum01 = 1.0/(ratio0+ratio1);
ratio0 *= invsum01;
ratio1 *= invsum01;
}
CDartOnEdge dart;
unsigned int id_e_add0 = 0;
{
dart.id_vc = cad_2d.AddVertex(Cad::LOOP,id_l,pos).id_v_add;
Cad::CCadObj2D::CResAddVertex res_add_out0 = cad_2d.AddVertex(Cad::EDGE,id_e0,out0);
dart.id_v1 = res_add_out0.id_v_add;
id_e_add0 = res_add_out0.id_e_add;
dart.id_v2 = cad_2d.AddVertex(Cad::EDGE,id_e0,out1).id_v_add;
dart.id_e1 = cad_2d.ConnectVertex_Line(dart.id_v1,dart.id_vc).id_e_add;
Cad::CBRepSurface::CResConnectVertex res;
if( is_same_dir0 ){ res = cad_2d.ConnectVertex_Line(dart.id_v2,dart.id_vc); }
else{ res = cad_2d.ConnectVertex_Line(dart.id_vc,dart.id_v2); }
dart.id_e2 = res.id_e_add;
dart.id_l = res.id_l_add;
dart.id_l_in = id_l;
dart.id_vo = 0;
}
if( pAnalysis != 0 ){
unsigned int id_e_add1 = 0;
unsigned int id_e_opp; bool is_same_dir_opp;
bool is_seam_line_cutted = false;
if( pAnalysis->IsSeamLine(id_e0,id_e_opp,is_same_dir_opp) ){
is_seam_line_cutted = true;
assert( cad_2d.IsElemID(Cad::EDGE,id_e_opp) );
unsigned int id_v_opp0, id_v_opp1;
cad_2d.GetIdVertex_Edge(id_v_opp0,id_v_opp1,id_e_opp);
Com::CVector2D opp0 = cad_2d.GetVertexCoord(id_v_opp0);
Com::CVector2D opp1 = cad_2d.GetVertexCoord(id_v_opp1);
Cad::CCadObj2D::CResAddVertex res1 = cad_2d.AddVertex(Cad::EDGE,id_e_opp,opp0*ratio0+opp1*ratio1);
id_e_add1 = res1.id_e_add;
dart.id_vo = res1.id_v_add;
}
aDartOnEdge.push_back(dart);
Solve_fromCad_InterpValue();
if( is_seam_line_cutted ){
pAnalysis->DisconnectEdge(id_e0,id_e_opp);
pAnalysis->ConnectEdge(this->cad_2d,this->mesh_2d,id_e0,id_e_add1);
pAnalysis->ConnectEdge(this->cad_2d,this->mesh_2d,id_e_add0,id_e_opp);
}
pAnalysis->ConnectEdge(this->cad_2d,this->mesh_2d,dart.id_e2,dart.id_e1);
this->InitDrawer();
if( pAnalysis->GetMode() != CLOTH_INITIAL_LOCATION ){
pAnalysis->PerformStaticSolver();
}
}
else{
aDartOnEdge.push_back(dart);
Solve_fromCad_InterpValue();
}
return dart.id_l;
}
bool FindIntersectionEdge
(const Cad::CCadObj2D& cad_2d,
unsigned int id_l,const Com::CVector2D& pos, const Com::CVector2D& poe,
unsigned int& id_e_nearest, bool& is_same_dir_e_near,
Com::CVector2D& p_nearest)
{
id_e_nearest = 0;
Com::CVector2D dir = poe-pos; dir.Normalize();
double sqdist = -1;
for(Cad::CBRepSurface::CItrLoop pItr = cad_2d.GetItrLoop(id_l);!pItr.IsEndChild();pItr.ShiftChildLoop()){
for(;!pItr.IsEnd();pItr++){
unsigned int id_e; bool is_same_dir;
pItr.GetIdEdge(id_e,is_same_dir);
const Cad::CEdge2D& edge = cad_2d.GetEdge(id_e);
Com::CVector2D sec;
if( !edge.GetNearestIntersectionPoint_AgainstHalfLine(sec,pos,dir) ) continue;
if( sqdist < 0 || (sec-pos).SqLength() < sqdist ){
id_e_nearest = id_e;
is_same_dir_e_near = is_same_dir;
p_nearest = sec;
sqdist = (sec-pos).SqLength();
}
}
}
if( !cad_2d.IsElemID(Cad::EDGE,id_e_nearest) ){ return false; }
return true;
}
unsigned int GetSymPairIdV(unsigned int id_v, const std::vector< std::pair<unsigned int,unsigned int> >& aPair){
for(unsigned int isym=0;isym<aPair.size();isym++){
if( aPair[isym].first == id_v ){ return aPair[isym].second; }
else if( aPair[isym].second == id_v ){ return aPair[isym].first; }
}
return 0;
}
bool CDesigner2D_Cloth::AddDartDiamond_Sym
(unsigned int id_l,const Com::CVector2D& pos0, const Com::CVector2D& poe0)
{
unsigned int id_l_dart0 = AddDartDiamond(id_l,pos0,poe0);
if( !cad_2d.IsElemID(Cad::LOOP,id_l_dart0) ) return false;
/////
double cnt_x;
{
double sum;
unsigned int n=0;
for(Cad::CBRepSurface::CItrLoop itrl = cad_2d.GetItrLoop(id_l);!itrl.IsEnd();itrl++){
unsigned int id_v = itrl.GetIdVertex();
unsigned int id_vo = GetSymPairIdV(id_v,aSymIdVPair);
if( id_vo == 0 ) continue;
sum += cad_2d.GetVertexCoord(id_v).x;
sum += cad_2d.GetVertexCoord(id_vo).x;
n+=2;
}
cnt_x = sum/n;
}
Com::CVector2D pos1(2*cnt_x-pos0.x,pos0.y);
Com::CVector2D poe1(2*cnt_x-poe0.x,poe0.y);
if( (pos1.x-cnt_x)*(poe1.x-cnt_x) < 0 ) return true;
unsigned int id_l_dart1 = AddDartDiamond(id_l,pos1,poe1);
if( !cad_2d.IsElemID(Cad::LOOP,id_l_dart1) ) return false;
int idart0=-1, idart1=-1;
for(unsigned int idart=0;idart<aDartDiamond.size();idart++){
if( aDartDiamond[idart].id_l == id_l_dart0 ){ idart0 = idart; }
if( aDartDiamond[idart].id_l == id_l_dart1 ){ idart1 = idart; }
}
if( idart0 == -1 && idart1 == -1 ) return true;
const CDartDiamond& dart0 = aDartDiamond[idart0];
const CDartDiamond& dart1 = aDartDiamond[idart1];
aSymIdVPair.push_back( std::make_pair(dart0.id_vu,dart1.id_vu) );
aSymIdVPair.push_back( std::make_pair(dart0.id_vd,dart1.id_vd) );
aSymIdVPair.push_back( std::make_pair(dart0.id_vl,dart1.id_vr) );
aSymIdVPair.push_back( std::make_pair(dart0.id_vr,dart1.id_vl) );
return true;
}
///////////////////////
bool CDesigner2D_Cloth::AddDartEdge_Sym
(unsigned id_l0,
const Com::CVector2D& pos0,
const Com::CVector2D& poe0)
{
unsigned int id_e0=0; bool is_same_dir0;
Com::CVector2D p0;
if( !FindIntersectionEdge(cad_2d,id_l0,pos0,poe0, id_e0,is_same_dir0, p0) ) return 0;
unsigned int id_v10,id_v20;
cad_2d.GetIdVertex_Edge(id_v10,id_v20,id_e0);
const unsigned int id_v1o = GetSymPairIdV(id_v10,aSymIdVPair);
const unsigned int id_v2o = GetSymPairIdV(id_v20,aSymIdVPair);
unsigned int id_l_dart0 = this->AddDartEdge(id_l0, id_e0,is_same_dir0, pos0,p0); // Add Dart0
if( !cad_2d.IsElemID(Cad::EDGE,id_l_dart0) ){ return false; }
if( id_v1o == 0 || id_v2o == 0 ) return true;
double cnt_x;
unsigned int id_l_dart1 = 0;
if( id_v1o == id_v20 ){ // dart in centered edge
assert( id_v2o == id_v10 );
{
const Com::CVector2D& vec10 = cad_2d.GetVertexCoord(id_v10);
const Com::CVector2D& vec20 = cad_2d.GetVertexCoord(id_v20);
cnt_x = (vec10.x + vec20.x)*0.5;
}
{
Com::CVector2D pos1(2*cnt_x-pos0.x,pos0.y);
Com::CVector2D poe1(2*cnt_x-poe0.x,poe0.y);
// if( (pos1.x-cnt_x)*(poe1.x-cnt_x) < -0.001 ) return true;
{
if( fabs(pos1.x-cnt_x) < 0.03 ) return true;
if( fabs(poe1.x-cnt_x) < 0.03 ) return true;
if( (pos1.x-cnt_x)*(poe1.x-cnt_x) < 0 ) return true;
}
unsigned int id_e1=0; bool is_same_dir1;
Com::CVector2D p1;
if( !FindIntersectionEdge(cad_2d,id_l0,pos1,poe1, id_e1,is_same_dir1, p1) ) return true;
id_l_dart1 = this->AddDartEdge(id_l0, id_e1,is_same_dir1, pos1,p1); // Add Dart1
}
}
else { // dart in side edge
{
const Com::CVector2D& vec10 = cad_2d.GetVertexCoord(id_v10);
const Com::CVector2D& vec20 = cad_2d.GetVertexCoord(id_v20);
const Com::CVector2D& vec1o = cad_2d.GetVertexCoord(id_v1o);
const Com::CVector2D& vec2o = cad_2d.GetVertexCoord(id_v2o);
cnt_x = (vec10.x + vec20.x + vec1o.x + vec2o.x)*0.25;
}
{
Com::CVector2D pos1(2*cnt_x-pos0.x,pos0.y);
Com::CVector2D poe1(2*cnt_x-poe0.x,poe0.y);
if( fabs(pos1.x-cnt_x) < 0.03 ) return true;
if( fabs(poe1.x-cnt_x) < 0.03 ) return true;
if( (pos1.x-cnt_x)*(poe1.x-cnt_x) < 0 ) return true;
unsigned int id_l1 = 0;
{
const std::vector<unsigned int>& aIdL = cad_2d.GetAryElemID(Cad::LOOP);
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
if( cad_2d.CheckIsPointInsideLoop(id_l,pos1) ){ id_l1 = id_l; break; }
}
}
unsigned int id_e1=0; bool is_same_dir1;
Com::CVector2D p1;
if( !FindIntersectionEdge(cad_2d,id_l1,pos1,poe1, id_e1,is_same_dir1, p1) ) return true;
id_l_dart1 = this->AddDartEdge(id_l1, id_e1,is_same_dir1, pos1,p1); // Add Dart1
}
}
if( !cad_2d.IsElemID(Cad::EDGE,id_l_dart1) ){ return true; }
int idart0=-1, idart1=-1;
for(unsigned int idart=0;idart<aDartOnEdge.size();idart++){
if( aDartOnEdge[idart].id_l == id_l_dart0 ){ idart0 = idart; }
if( aDartOnEdge[idart].id_l == id_l_dart1 ){ idart1 = idart; }
}
if( idart0 == -1 && idart1 == -1 ) return true;
const CDartOnEdge& dart0 = aDartOnEdge[idart0];
const CDartOnEdge& dart1 = aDartOnEdge[idart1];
aSymIdVPair.push_back( std::make_pair(dart0.id_vc,dart1.id_vc) );
aSymIdVPair.push_back( std::make_pair(dart0.id_vo,dart1.id_vo) );
{
const Com::CVector2D& vec10 = cad_2d.GetVertexCoord(dart0.id_v1);
const Com::CVector2D& vec20 = cad_2d.GetVertexCoord(dart0.id_v2);
const Com::CVector2D& vec11 = cad_2d.GetVertexCoord(dart1.id_v1);
const Com::CVector2D& vec21 = cad_2d.GetVertexCoord(dart1.id_v2);
const Com::CVector2D vec10o(2*cnt_x-vec10.x,vec10.y);
const Com::CVector2D vec20o(2*cnt_x-vec20.x,vec20.y);
double sum0 = Com::Distance(vec10o,vec11) + Com::Distance(vec20o,vec21);
double sum1 = Com::Distance(vec10o,vec21) + Com::Distance(vec20o,vec11);
if( sum0 < sum1 ){
aSymIdVPair.push_back( std::make_pair(dart0.id_v1,dart1.id_v1) );
aSymIdVPair.push_back( std::make_pair(dart0.id_v2,dart1.id_v2) );
}
else{
aSymIdVPair.push_back( std::make_pair(dart0.id_v1,dart1.id_v2) );
aSymIdVPair.push_back( std::make_pair(dart0.id_v2,dart1.id_v1) );
}
}
return true;
}
bool CDesigner2D_Cloth::Cad_AddHole(const Com::CVector2D& pos, const Com::CVector2D& poe)
{
// pAnalysis->SetClothPiecePlacingMode();
unsigned int id_ls = 0, id_le = 0;
{
const std::vector<unsigned int>& aIdL = cad_2d.GetAryElemID(Cad::LOOP);
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
if( cad_2d.CheckIsPointInsideLoop(id_l,pos) ){ id_ls = id_l; break; }
}
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
if( cad_2d.CheckIsPointInsideLoop(id_l,poe) ){ id_le = id_l; break; }
}
}
////
if( id_ls == 0 || id_le == 0 || id_ls != id_le ){ return true; }
const unsigned int id_l = id_ls;
if( !mesh_2d.IsIdLCad_CutMesh(id_l) ) return 0;
Com::CVector2D po1,po2,po3,po4;
{
double min_x = ( pos.x < poe.x ) ? pos.x : poe.x;
double max_x = ( pos.x > poe.x ) ? pos.x : poe.x;
double min_y = ( pos.y < poe.y ) ? pos.y : poe.y;
double max_y = ( pos.y > poe.y ) ? pos.y : poe.y;
po1 = Com::CVector2D(min_x,min_y);
po2 = Com::CVector2D(max_x,min_y);
po3 = Com::CVector2D(max_x,max_y);
po4 = Com::CVector2D(min_x,max_y);
}
if( !cad_2d.CheckIsPointInsideLoop(id_l,po1) ) return 0;
if( !cad_2d.CheckIsPointInsideLoop(id_l,po2) ) return 0;
if( !cad_2d.CheckIsPointInsideLoop(id_l,po3) ) return 0;
if( !cad_2d.CheckIsPointInsideLoop(id_l,po4) ) return 0;
std::vector< Com::CVector2D > aVec;
aVec.push_back(po1);
aVec.push_back(po2);
aVec.push_back(po3);
aVec.push_back(po4);
// const unsigned int id_l_add = cad_2d.AddPolygon(aVec,id_l).id_l_add;
const Cad::CCadObj2D::CResAddPolygon& res = cad_2d.AddPolygon(aVec,id_l);
const unsigned int id_l_add = res.id_l_add;
if( id_l_add == 0 ){ return 0; }
Solve_fromCad_InterpValue();
this->InitDrawer();
return id_l_add;
}
bool CDesigner2D_Cloth::Cad_AddCutLine(const Com::CVector2D& pos, const Com::CVector2D& poe)
{
// pAnalysis->SetClothPiecePlacingMode();
unsigned int id_ls = 0, id_le = 0;
{
const std::vector<unsigned int>& aIdL = cad_2d.GetAryElemID(Cad::LOOP);
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
if( cad_2d.CheckIsPointInsideLoop(id_l,pos) ){ id_ls = id_l; break; }
}
for(unsigned int iidl=0;iidl<aIdL.size();iidl++){
unsigned int id_l = aIdL[iidl];
if( cad_2d.CheckIsPointInsideLoop(id_l,poe) ){ id_le = id_l; break; }
}
}
////
if( id_ls > 0 && id_le > 0 && id_ls == id_le ){ // diamond dart