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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
|
/*************************************************************************
*
* $RCSfile: view3d.cxx,v $
*
* $Revision: 1.13 $
*
* last change: $Author: thb $ $Date: 2001-07-17 07:04:30 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#define ITEMID_COLOR 0
#ifndef _SV_WRKWIN_HXX
#include <vcl/wrkwin.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_OPTIONS3D_HXX
#include <svtools/options3d.hxx>
#endif
#ifndef _SVDOGRP_HXX
#include "svdogrp.hxx"
#endif
#ifndef _SVDOPATH_HXX
#include "svdopath.hxx"
#endif
#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif
#ifndef _SVDITER_HXX
#include "svditer.hxx"
#endif
#ifndef _SVDPOOL_HXX
#include "svdpool.hxx"
#endif
#ifndef _SVDORECT_HXX
#include "svdorect.hxx"
#endif
#ifndef _SVDMODEL_HXX
#include "svdmodel.hxx"
#endif
#ifndef _SVDPAGV_HXX
#include "svdpagv.hxx"
#endif
#ifndef _XOUTX_HXX
#include "xoutx.hxx"
#endif
#ifndef _SVX_SVXIDS_HRC
#include <svxids.hrc>
#endif
#ifndef _SVX_COLRITEM_HXX
#include "colritem.hxx"
#endif
#ifndef _XTABLE_HXX
#include "xtable.hxx"
#endif
#ifndef _SVDVIEW_HXX
#include "svdview.hxx"
#endif
#ifndef _SVX_DIALOGS_HRC
#include "dialogs.hrc"
#endif
#ifndef _SVX_DIALMGR_HXX
#include "dialmgr.hxx"
#endif
#ifndef _E3D_GLOBL3D_HXX
#include "globl3d.hxx"
#endif
#ifndef _E3D_OBJ3D_HXX
#include "obj3d.hxx"
#endif
#ifndef _E3D_LATHE3D_HXX
#include "lathe3d.hxx"
#endif
#ifndef _E3D_SPHERE3D_HXX
#include "sphere3d.hxx"
#endif
#ifndef _E3D_EXTRUD3D_HXX
#include "extrud3d.hxx"
#endif
#ifndef _E3D_CUBE3D_HXX
#include "cube3d.hxx"
#endif
#ifndef _E3D_POLYOB3D_HXX
#include "polyob3d.hxx"
#endif
#ifndef _E3D_DLIGHT3D_HXX
#include "dlight3d.hxx"
#endif
#ifndef _E3D_POLYSC3D_HXX
#include "polysc3d.hxx"
#endif
#ifndef _E3D_DRAGMT3D_HXX
#include "dragmt3d.hxx"
#endif
#ifndef _E3D_VIEW3D_HXX
#include "view3d.hxx"
#endif
#ifndef _SVDUNDO_HXX
#include "svdundo.hxx"
#endif
#ifndef _SVX_XFLCLIT_HXX
#include "xflclit.hxx"
#endif
#ifndef _SVX_XLNCLIT_HXX
#include "xlnclit.hxx"
#endif
#ifndef _SVDOGRAF_HXX
#include <svdograf.hxx>
#endif
#ifndef _SVX_XBTMPIT_HXX
#include <xbtmpit.hxx>
#endif
#ifndef _SVX_XFLBMTIT_HXX
#include <xflbmtit.hxx>
#endif
#include "xlnwtit.hxx"
#define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
TYPEINIT1(E3dView, SdrView);
long Scalar (Point aPoint1,
Point aPoint2);
Point ScaleVector (Point aPoint,
double nScale);
double NormVector (Point aPoint);
BOOL LineCutting (Point aP1,
Point aP2,
Point aP3,
Point aP4);
long Point2Line (Point aP1,
Point aP2,
Point aP3);
long DistPoint2Line (Point u,
Point v1,
Point v);
/*************************************************************************
|*
|* Konstruktor 1
|*
\************************************************************************/
E3dView::E3dView(SdrModel* pModel, OutputDevice* pOut) :
SdrView(pModel, pOut)
{
InitView ();
}
/*************************************************************************
|*
|* Konstruktor 2
|*
\************************************************************************/
E3dView::E3dView(SdrModel* pModel, ExtOutputDevice* pExtOut) :
SdrView(pModel, pExtOut)
{
InitView ();
}
/*************************************************************************
|*
|* Konstruktor 3
|*
\************************************************************************/
E3dView::E3dView(SdrModel* pModel) :
SdrView(pModel)
{
InitView ();
}
/*************************************************************************
|*
|* DrawMarkedObj ueberladen, da eventuell nur einzelne 3D-Objekte
|* gezeichnet werden sollen
|*
\************************************************************************/
void E3dView::DrawMarkedObj(OutputDevice& rOut, const Point& rOfs) const
{
// Existieren 3D-Objekte, deren Szenen nicht selektiert sind?
BOOL bSpecialHandling = FALSE;
E3dScene *pScene = NULL;
long nCnt = aMark.GetMarkCount();
for(long nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene && !IsObjMarked(pScene))
bSpecialHandling = TRUE;
}
// Alle SelectionFlags zuruecksetzen
if(pObj && pObj->ISA(E3dObject))
{
pScene = ((E3dObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
if(bSpecialHandling)
{
// SelectionFlag bei allen zu 3D Objekten gehoerigen
// Szenen und deren Objekten auf nicht selektiert setzen
long nObjs;
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
// bei allen direkt selektierten Objekten auf selektiert setzen
SdrMark* pM = NULL;
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dObject))
{
// Objekt markieren
E3dObject* p3DObj = (E3dObject*)pObj;
p3DObj->SetSelected(TRUE);
pScene = p3DObj->GetScene();
pM = aMark.GetMark(nObjs);
}
}
if(pScene)
{
// code from parent
((E3dView*)this)->aMark.ForceSort();
pXOut->SetOutDev(&rOut);
SdrPaintInfoRec aInfoRec;
aInfoRec.nPaintMode|=SDRPAINTMODE_ANILIKEPRN;
Point aOfs(-rOfs.X(), -rOfs.Y());
aOfs += pM->GetPageView()->GetOffset();
if(aOfs != pXOut->GetOffset())
pXOut->SetOffset(aOfs);
pScene->SetDrawOnlySelected(TRUE);
pScene->Paint(*pXOut,aInfoRec);
pScene->SetDrawOnlySelected(FALSE);
pXOut->SetOffset(Point(0,0));
}
// SelectionFlag zuruecksetzen
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
}
else
{
// call parent
SdrExchangeView::DrawMarkedObj(rOut, rOfs);
}
}
/*************************************************************************
|*
|* Model holen ueberladen, da bei einzelnen 3D Objekten noch eine Szene
|* untergeschoben werden muss
|*
\************************************************************************/
SdrModel* E3dView::GetMarkedObjModel() const
{
// Existieren 3D-Objekte, deren Szenen nicht selektiert sind?
BOOL bSpecialHandling = FALSE;
E3dScene *pScene = NULL;
long nCnt = aMark.GetMarkCount();
for(long nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene && !IsObjMarked(pScene))
bSpecialHandling = TRUE;
}
// Alle SelectionFlags zuruecksetzen
if(pObj && pObj->ISA(E3dObject))
{
pScene = ((E3dObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
SdrModel* pNewModel = 0L;
if(bSpecialHandling)
{
// SelectionFlag bei allen zu 3D Objekten gehoerigen
// Szenen und deren Objekten auf nicht selektiert setzen
long nObjs;
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
// bei allen direkt selektierten Objekten auf selektiert setzen
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dObject))
{
// Objekt markieren
E3dObject* p3DObj = (E3dObject*)pObj;
p3DObj->SetSelected(TRUE);
}
}
// Neue MarkList generieren, die die betroffenen
// Szenen als markierte Objekte enthaelt
SdrMarkList aOldML(aMark); // alte Marklist merken
SdrMarkList aNewML; // neue leere Marklist
((E3dView*)this)->aMark = aNewML;
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aOldML.GetMark(nObjs)->GetObj();
if(pObj)
{
if(pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene holen
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene)
pObj = pScene;
}
// Keine Objekte doppelt markieren
// (dies koennten nur Szenen sein)
if(!IsObjMarked(pObj))
{
USHORT nAnz=GetPageViewCount();
for (USHORT nv=0; nv<nAnz; nv++) {
SdrPageView* pPV=GetPageViewPvNum(nv);
((E3dView*)this)->MarkObj(pObj,pPV,FALSE,TRUE);
}
}
}
}
// call parent
pNewModel = SdrView::GetMarkedObjModel();
// Alle Szenen im kopierten Model in Ihren Ausdehnungen Korrigieren
// und IsSelected zuruecksetzen
if(pNewModel)
{
for(UINT16 nPg=0; nPg < pNewModel->GetPageCount(); nPg++)
{
const SdrPage* pSrcPg=pNewModel->GetPage(nPg);
UINT32 nObAnz=pSrcPg->GetObjCount();
// Unterobjekte von Szenen einfuegen
for(UINT32 nOb=0; nOb<nObAnz; nOb++)
{
const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
if(pSrcOb->ISA(E3dScene))
{
pScene = (E3dScene*)pSrcOb;
pScene->CorrectSceneDimensions();
pScene->SetSelected(FALSE);
}
}
}
}
// Alte Liste wieder setzen
((E3dView*)this)->aMark = aOldML;
// SelectionFlag zuruecksetzen
for(nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
{
// zugehoerige Szene
pScene = ((E3dCompoundObject*)pObj)->GetScene();
if(pScene)
pScene->SetSelected(FALSE);
}
}
}
else
{
// call parent
pNewModel = SdrView::GetMarkedObjModel();
}
// model zurueckgeben
return pNewModel;
}
/*************************************************************************
|*
|* Bei Paste muss - falls in eine Scene eingefuegt wird - die
|* Objekte der Szene eingefuegt werden, die Szene selbst aber nicht
|*
\************************************************************************/
BOOL E3dView::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, UINT32 nOptions)
{
BOOL bRetval = FALSE;
// Liste holen
Point aPos(rPos);
SdrObjList* pDstList = pLst;
ImpGetPasteObjList(aPos, pDstList);
if(!pDstList)
return FALSE;
// Owner der Liste holen
SdrObject* pOwner = pDstList->GetOwnerObj();
if(pOwner && pOwner->ISA(E3dScene))
{
E3dScene* pDstScene = (E3dScene*)pOwner;
BOOL bDstInserted(FALSE);
BegUndo(SVX_RESSTR(RID_SVX_3D_UNDO_EXCHANGE_PASTE));
// Alle Objekte aus E3dScenes kopieren und direkt einfuegen
for(sal_uInt16 nPg(0); nPg < rMod.GetPageCount(); nPg++)
{
const SdrPage* pSrcPg=rMod.GetPage(nPg);
sal_uInt32 nObAnz(pSrcPg->GetObjCount());
// calculate offset for paste
Rectangle aR = pSrcPg->GetAllObjBoundRect();
Point aDist(aPos - aR.Center());
// Unterobjekte von Szenen einfuegen
for(sal_uInt32 nOb(0); nOb < nObAnz; nOb++)
{
const SdrObject* pSrcOb = pSrcPg->GetObj(nOb);
if(pSrcOb->ISA(E3dScene))
{
E3dScene* pSrcScene = (E3dScene*)pSrcOb;
bDstInserted = ImpCloneAll3DObjectsToDestScene(pSrcScene, pDstScene, aDist);
}
}
}
EndUndo();
// DestScene anpassen
if(bDstInserted)
{
pDstScene->SetRectsDirty();
pDstScene->CorrectSceneDimensions();
bRetval = TRUE;
}
}
else
{
// call parent
bRetval = SdrView::Paste(rMod, rPos, pLst, nOptions);
}
// und Rueckgabewert liefern
return bRetval;
}
// #83403# Service routine used from local Clone() and from SdrCreateView::EndCreateObj(...)
BOOL E3dView::ImpCloneAll3DObjectsToDestScene(E3dScene* pSrcScene, E3dScene* pDstScene, Point aOffset)
{
BOOL bRetval(FALSE);
if(pSrcScene && pDstScene)
{
B3dCamera& rCameraSetDst = pDstScene->GetCameraSet();
B3dCamera& rCameraSetSrc = pSrcScene->GetCameraSet();
for(sal_uInt32 i(0); i < pSrcScene->GetSubList()->GetObjCount(); i++)
{
SdrObject* pObj = pSrcScene->GetSubList()->GetObj(i);
if(pObj && pObj->ISA(E3dCompoundObject))
{
// Kopieren
E3dObject* pNew = (E3dObject*)pObj->Clone(pDstScene->GetPage(), pDstScene->GetModel());
if(pNew)
{
// Neues Objekt in Szene einfuegen
pNew->NbcSetLayer(pObj->GetLayer());
pNew->NbcSetStyleSheet(pObj->GetStyleSheet(), TRUE);
pDstScene->Insert3DObj(pNew);
bRetval = TRUE;
// Transformation ObjectToEye Src
Matrix4D aMatSrc;
aMatSrc = ((E3dCompoundObject*)pObj)->GetFullTransform();
aMatSrc *= rCameraSetSrc.GetOrientation();
// Tanslation und scale von source
B3dVolume aDevVolSrc = rCameraSetSrc.GetDeviceVolume();
// auf Augkoordinaten umstellen
double fTemp = aDevVolSrc.MinVec().Z();
aDevVolSrc.MinVec().Z() = -aDevVolSrc.MaxVec().Z();
aDevVolSrc.MaxVec().Z() = -fTemp;
Vector3D aProjScaleSrc(
2.0 / aDevVolSrc.GetWidth(),
2.0 / aDevVolSrc.GetHeight(),
2.0 / aDevVolSrc.GetDepth());
Vector3D aProjTransSrc(
-1.0 * ((aDevVolSrc.MaxVec().X() + aDevVolSrc.MinVec().X()) / aDevVolSrc.GetWidth()),
-1.0 * ((aDevVolSrc.MaxVec().Y() + aDevVolSrc.MinVec().Y()) / aDevVolSrc.GetHeight()),
-1.0 * ((aDevVolSrc.MaxVec().Z() + aDevVolSrc.MinVec().Z()) / aDevVolSrc.GetDepth()));
Vector3D aViewScaleSrc(rCameraSetSrc.GetScale());
aViewScaleSrc.Z() = 1.0;
// Tanslation und scale von dest
B3dVolume aDevVolDst = rCameraSetDst.GetDeviceVolume();
// auf Augkoordinaten umstellen
fTemp = aDevVolDst.MinVec().Z();
aDevVolDst.MinVec().Z() = -aDevVolDst.MaxVec().Z();
aDevVolDst.MaxVec().Z() = -fTemp;
Vector3D aProjScaleDst(
2.0 / aDevVolDst.GetWidth(),
2.0 / aDevVolDst.GetHeight(),
2.0 / aDevVolDst.GetDepth());
Vector3D aProjTransDst(
-1.0 * ((aDevVolDst.MaxVec().X() + aDevVolDst.MinVec().X()) / aDevVolDst.GetWidth()),
-1.0 * ((aDevVolDst.MaxVec().Y() + aDevVolDst.MinVec().Y()) / aDevVolDst.GetHeight()),
-1.0 * ((aDevVolDst.MaxVec().Z() + aDevVolDst.MinVec().Z()) / aDevVolDst.GetDepth()));
Vector3D aViewScaleDst(rCameraSetDst.GetScale());
aViewScaleDst.Z() = 1.0;
// Groesse des Objektes in Augkoordinaten Src
Volume3D aObjVolSrc;
aObjVolSrc.Union(((E3dCompoundObject*)pObj)->GetBoundVolume().GetTransformVolume(aMatSrc));
// Vorlaeufige Groesse in Augkoordinaten Dst
Matrix4D aMatZwi = aMatSrc;
aMatZwi.Scale(aProjScaleSrc);
aMatZwi.Translate(aProjTransSrc);
aMatZwi.Scale(aViewScaleSrc);
Matrix4D aMatDst;
aMatDst.Scale(aProjScaleDst);
aMatDst.Translate(aProjTransDst);
aMatDst.Scale(aViewScaleDst);
aMatDst.Invert();
aMatZwi *= aMatDst;
Volume3D aObjVolDst;
aObjVolDst.Union(((E3dCompoundObject*)pObj)->GetBoundVolume().GetTransformVolume(aMatZwi));
// Beide verhaeltnistiefen berechnen und mitteln
double fDepthOne = (aObjVolSrc.GetDepth() * aObjVolDst.GetWidth()) / aObjVolSrc.GetWidth();
double fDepthTwo = (aObjVolSrc.GetDepth() * aObjVolDst.GetHeight()) / aObjVolSrc.GetHeight();
double fWantedDepth = (fDepthOne + fDepthTwo) / 2.0;
// Faktor zum Tiefe anpassen bilden
double fFactor = fWantedDepth / aObjVolDst.GetDepth();
Vector3D aDepthScale(1.0, 1.0, fFactor);
// Endgueltige Transformation bilden
aMatSrc.Scale(aProjScaleSrc);
aMatSrc.Translate(aProjTransSrc);
aMatSrc.Scale(aViewScaleSrc);
aMatSrc.Scale(aDepthScale);
aMatDst = pDstScene->GetFullTransform();
aMatDst *= rCameraSetDst.GetOrientation();
aMatDst.Scale(aProjScaleDst);
aMatDst.Translate(aProjTransDst);
aMatDst.Scale(aViewScaleDst);
aMatDst.Invert();
aMatSrc *= aMatDst;
// Neue Objekttransformation setzen
pNew->SetTransform(aMatSrc);
// force new camera and SnapRect on scene, geometry may have really
// changed
pDstScene->CorrectSceneDimensions();
// #83403# translate in view coor
{
// screen position of center of old object
Matrix4D aSrcFullTrans = ((E3dCompoundObject*)pObj)->GetFullTransform();
rCameraSetSrc.SetObjectTrans(aSrcFullTrans);
Vector3D aSrcCenter = ((E3dCompoundObject*)pObj)->GetCenter();
aSrcCenter = rCameraSetSrc.ObjectToViewCoor(aSrcCenter);
if(aOffset.X() != 0 || aOffset.Y() != 0)
aSrcCenter += Vector3D((double)aOffset.X(), (double)aOffset.Y(), 0.0);
// to have a valid Z-Coor in dst system, calc current center of dst object
Matrix4D aDstFullTrans = pNew->GetFullTransform();
rCameraSetDst.SetObjectTrans(aDstFullTrans);
Vector3D aDstCenter = pNew->GetCenter();
aDstCenter = rCameraSetDst.ObjectToEyeCoor(aDstCenter);
// convert aSrcCenter to a eye position of dst scene
Vector3D aNewDstCenter = rCameraSetDst.ViewToEyeCoor(aSrcCenter);
aNewDstCenter.Z() = aDstCenter.Z();
// transform back to object coor
aNewDstCenter = rCameraSetDst.EyeToObjectCoor(aNewDstCenter);
// get transform vector
Vector3D aTransformCorrection = aNewDstCenter - pNew->GetCenter();
Matrix4D aTransCorrMat;
aTransCorrMat.Translate(aTransformCorrection);
// treanslate new object, add translate in front of obj transform
pNew->SetTransform(aTransCorrMat * pNew->GetTransform());
// force new camera and SnapRect on scene, geometry may have really
// changed
pDstScene->CorrectSceneDimensions();
//Rectangle aOldPosSize = pObj->GetSnapRect();
//if(aOffset.X() != 0 || aOffset.Y() != 0)
// aOldPosSize.Move(aOffset.X(), aOffset.Y());
//Rectangle aNewPosSize = pNew->GetSnapRect();
}
// Undo anlegen
AddUndo(new SdrUndoNewObj(*pNew));
}
}
}
}
return bRetval;
}
/*************************************************************************
|*
|* 3D-Konvertierung moeglich?
|*
\************************************************************************/
BOOL E3dView::IsConvertTo3DObjPossible() const
{
BOOL bAny3D(FALSE);
BOOL bGroupSelected(FALSE);
BOOL bRetval(TRUE);
for(sal_uInt32 a=0;!bAny3D && a<aMark.GetMarkCount();a++)
{
SdrObject *pObj = aMark.GetMark(a)->GetObj();
if(pObj)
{
ImpIsConvertTo3DPossible(pObj, bAny3D, bGroupSelected);
}
}
bRetval = !bAny3D
&& (
IsConvertToPolyObjPossible(FALSE)
|| IsConvertToPathObjPossible(FALSE)
|| IsImportMtfPossible());
return bRetval;
}
void E3dView::ImpIsConvertTo3DPossible(SdrObject* pObj, BOOL& rAny3D,
BOOL& rGroupSelected) const
{
if(pObj)
{
if(pObj->ISA(E3dObject))
{
rAny3D = TRUE;
}
else
{
if(pObj->IsGroupObject())
{
SdrObjListIter aIter(*pObj, IM_DEEPNOGROUPS);
while(aIter.IsMore())
{
SdrObject* pNewObj = aIter.Next();
ImpIsConvertTo3DPossible(pNewObj, rAny3D, rGroupSelected);
}
rGroupSelected = TRUE;
}
}
}
}
/*************************************************************************
|*
|* 3D-Konvertierung zu Extrude ausfuehren
|*
\************************************************************************/
#ifndef _EEITEM_HXX
#include "eeitem.hxx"
#endif
void E3dView::ImpChangeSomeAttributesFor3DConversion(SdrObject* pObj)
{
if(pObj->ISA(SdrTextObj))
{
const SfxItemSet& rSet = pObj->GetItemSet();
const SvxColorItem& rTextColorItem = (const SvxColorItem&)rSet.Get(EE_CHAR_COLOR);
if(rTextColorItem.GetValue() == RGB_Color(COL_BLACK))
{
// Bei schwarzen Textobjekten wird die Farbe auf grau gesetzt
if(pObj->GetPage())
{
// #84864# if black is only default attribute from
// pattern set it hard so that it is used in undo.
pObj->SetItem(SvxColorItem(RGB_Color(COL_BLACK), EE_CHAR_COLOR));
// add undo now
AddUndo(new SdrUndoAttrObj(*pObj, FALSE, FALSE));
}
pObj->SetItem(SvxColorItem(RGB_Color(COL_GRAY), EE_CHAR_COLOR));
}
}
}
void E3dView::ImpChangeSomeAttributesFor3DConversion2(SdrObject* pObj)
{
if(pObj->ISA(SdrPathObj))
{
const SfxItemSet& rSet = pObj->GetItemSet();
sal_Int32 nLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue();
XLineStyle eLineStyle = (XLineStyle)((const XLineStyleItem&)rSet.Get(XATTR_LINESTYLE)).GetValue();
XFillStyle eFillStyle = ITEMVALUE(rSet, XATTR_FILLSTYLE, XFillStyleItem);
if(((SdrPathObj*)pObj)->IsClosed()
&& eLineStyle == XLINE_SOLID
&& !nLineWidth
&& eFillStyle != XFILL_NONE)
{
if(pObj->GetPage())
AddUndo(new SdrUndoAttrObj(*pObj, FALSE, FALSE));
pObj->SetItem(XLineStyleItem(XLINE_NONE));
pObj->SetItem(XLineWidthItem(0L));
}
}
}
void E3dView::ImpCreateSingle3DObjectFlat(E3dScene* pScene, SdrObject* pObj, BOOL bExtrude, double fDepth, Matrix4D& rLatheMat)
{
// Einzelnes PathObject, dieses umwanden
SdrPathObj* pPath = PTR_CAST(SdrPathObj, pObj);
if(pPath)
{
E3dDefaultAttributes aDefault = Get3DDefaultAttributes();
if(bExtrude)
aDefault.SetDefaultExtrudeCharacterMode(TRUE);
else
aDefault.SetDefaultLatheCharacterMode(TRUE);
// ItemSet des Ursprungsobjektes holen
SfxItemSet aSet(pObj->GetItemSet());
XFillStyle eFillStyle = ITEMVALUE(aSet, XATTR_FILLSTYLE, XFillStyleItem);
// Linienstil ausschalten
aSet.Put(XLineStyleItem(XLINE_NONE));
// Feststellen, ob ein FILL_Attribut gesetzt ist.
if(!pPath->IsClosed() || eFillStyle == XFILL_NONE)
{
// Das SdrPathObj ist nicht gefuellt, lasse die
// vordere und hintere Flaeche weg. Ausserdem ist
// eine beidseitige Darstellung notwendig.
aDefault.SetDefaultExtrudeCloseFront(FALSE);
aDefault.SetDefaultExtrudeCloseBack(FALSE);
aSet.Put(Svx3DDoubleSidedItem(TRUE));
// Fuellattribut setzen
aSet.Put(XFillStyleItem(XFILL_SOLID));
// Fuellfarbe muss auf Linienfarbe, da das Objekt vorher
// nur eine Linie war
Color aColorLine = ((const XLineColorItem&)(aSet.Get(XATTR_LINECOLOR))).GetValue();
aSet.Put(XFillColorItem(String(), aColorLine));
}
// Neues Extrude-Objekt erzeugen
E3dObject* p3DObj = NULL;
if(bExtrude)
{
p3DObj = new E3dExtrudeObj(aDefault, pPath->GetPathPoly(), fDepth);
}
else
{
PolyPolygon3D aPolyPoly3D(pPath->GetPathPoly(), aDefault.GetDefaultLatheScale());
aPolyPoly3D.Transform(rLatheMat);
p3DObj = new E3dLatheObj(aDefault, aPolyPoly3D);
}
// Attribute setzen
if(p3DObj)
{
p3DObj->NbcSetLayer(pObj->GetLayer());
p3DObj->SetItemSet(aSet);
p3DObj->NbcSetStyleSheet(pObj->GetStyleSheet(), TRUE);
// Neues 3D-Objekt einfuegen
pScene->Insert3DObj(p3DObj);
}
}
}
void E3dView::ImpCreate3DObject(E3dScene* pScene, SdrObject* pObj, BOOL bExtrude, double fDepth, Matrix4D& rLatheMat)
{
if(pObj)
{
// change text color attribute for not so dark colors
if(pObj->IsGroupObject())
{
SdrObjListIter aIter(*pObj, IM_DEEPWITHGROUPS);
while(aIter.IsMore())
{
SdrObject* pGroupMember = aIter.Next();
ImpChangeSomeAttributesFor3DConversion(pGroupMember);
}
}
else
ImpChangeSomeAttributesFor3DConversion(pObj);
// convert completely to path objects
SdrObject* pNewObj1 = pObj->ConvertToPolyObj(FALSE, FALSE);
if(pNewObj1)
{
// change text color attribute for not so dark colors
if(pNewObj1->IsGroupObject())
{
SdrObjListIter aIter(*pNewObj1, IM_DEEPWITHGROUPS);
while(aIter.IsMore())
{
SdrObject* pGroupMember = aIter.Next();
ImpChangeSomeAttributesFor3DConversion2(pGroupMember);
}
}
else
ImpChangeSomeAttributesFor3DConversion2(pNewObj1);
// convert completely to path objects
SdrObject* pNewObj2 = pObj->ConvertToContourObj(pNewObj1, TRUE);
if(pNewObj2)
{
// add all to flat scene
if(pNewObj2->IsGroupObject())
{
SdrObjListIter aIter(*pNewObj2, IM_DEEPWITHGROUPS);
while(aIter.IsMore())
{
SdrObject* pGroupMember = aIter.Next();
ImpCreateSingle3DObjectFlat(pScene, pGroupMember, bExtrude, fDepth, rLatheMat);
}
}
else
ImpCreateSingle3DObjectFlat(pScene, pNewObj2, bExtrude, fDepth, rLatheMat);
// delete zwi object
if(pNewObj2 != pObj && pNewObj2 != pNewObj1 && pNewObj2)
delete pNewObj2;
}
// delete zwi object
if(pNewObj1 != pObj && pNewObj1)
delete pNewObj1;
}
}
}
/*************************************************************************
|*
|* 3D-Konvertierung zu Extrude steuern
|*
\************************************************************************/
void E3dView::ConvertMarkedObjTo3D(BOOL bExtrude, Vector3D aPnt1, Vector3D aPnt2)
{
if(HasMarkedObj())
{
// Undo anlegen
if(bExtrude)
BegUndo(SVX_RESSTR(RID_SVX_3D_UNDO_EXTRUDE));
else
BegUndo(SVX_RESSTR(RID_SVX_3D_UNDO_LATHE));
// Neue Szene fuer zu erzeugende 3D-Objekte anlegen
E3dScene* pScene = new E3dPolyScene(Get3DDefaultAttributes());
// Rechteck bestimmen und evtl. korrigieren
Rectangle aRect = GetAllMarkedRect();
if(aRect.GetWidth() <= 1)
aRect.SetSize(Size(500, aRect.GetHeight()));
if(aRect.GetHeight() <= 1)
aRect.SetSize(Size(aRect.GetWidth(), 500));
// Tiefe relativ zur Groesse der Selektion bestimmen
double fDepth = 0.0;
double fRot3D = 0.0;
Matrix4D aLatheMat;
if(bExtrude)
{
double fW = (double)aRect.GetWidth();
double fH = (double)aRect.GetHeight();
fDepth = sqrt(fW*fW + fH*fH) / 6.0;
}
if(!bExtrude)
{
// Transformation fuer Polygone Rotationskoerper erstellen
if(aPnt1 != aPnt2)
{
// Rotation um Kontrollpunkt1 mit eigestelltem Winkel
// fuer 3D Koordinaten
Vector3D aDiff = aPnt1 - aPnt2;
fRot3D = atan2(aDiff.Y(), aDiff.X()) - F_PI2;
if(fabs(fRot3D) < SMALL_DVALUE)
fRot3D = 0.0;
if(fRot3D != 0.0)
{
aLatheMat.Translate(-aPnt2);
aLatheMat.RotateZ(-fRot3D);
aLatheMat.Translate(aPnt2);
}
}
if(aPnt2.X() != 0.0)
{
// Translation auf Y=0 - Achse
aLatheMat.TranslateX(-aPnt2.X());
}
else
{
aLatheMat.Translate((double)-aRect.Left());
}
// Inverse Matrix bilden, um die Zielausdehnung zu bestimmen
Matrix4D aInvLatheMat = aLatheMat;
aInvLatheMat.Invert();
// SnapRect Ausdehnung mittels Spiegelung an der Rotationsachse
// erweitern
for(UINT32 a=0;a<aMark.GetMarkCount();a++)
{
SdrMark* pMark = aMark.GetMark(a);
SdrObject* pObj = pMark->GetObj();
Rectangle aTurnRect = pObj->GetSnapRect();
Vector3D aRot;
Point aRotPnt;
aRot = Vector3D(aTurnRect.Left(), -aTurnRect.Top(), 0.0);
aRot *= aLatheMat;
aRot.X() = -aRot.X();
aRot *= aInvLatheMat;
aRotPnt = Point((long)(aRot.X() + 0.5), (long)(-aRot.Y() - 0.5));
aRect.Union(Rectangle(aRotPnt, aRotPnt));
aRot = Vector3D(aTurnRect.Left(), -aTurnRect.Bottom(), 0.0);
aRot *= aLatheMat;
aRot.X() = -aRot.X();
aRot *= aInvLatheMat;
aRotPnt = Point((long)(aRot.X() + 0.5), (long)(-aRot.Y() - 0.5));
aRect.Union(Rectangle(aRotPnt, aRotPnt));
aRot = Vector3D(aTurnRect.Right(), -aTurnRect.Top(), 0.0);
aRot *= aLatheMat;
aRot.X() = -aRot.X();
aRot *= aInvLatheMat;
aRotPnt = Point((long)(aRot.X() + 0.5), (long)(-aRot.Y() - 0.5));
aRect.Union(Rectangle(aRotPnt, aRotPnt));
aRot = Vector3D(aTurnRect.Right(), -aTurnRect.Bottom(), 0.0);
aRot *= aLatheMat;
aRot.X() = -aRot.X();
aRot *= aInvLatheMat;
aRotPnt = Point((long)(aRot.X() + 0.5), (long)(-aRot.Y() - 0.5));
aRect.Union(Rectangle(aRotPnt, aRotPnt));
}
}
// Ueber die Selektion gehen und in 3D wandeln, komplett mit
// Umwandeln in SdrPathObject, auch Schriften
for(UINT32 a=0;a<aMark.GetMarkCount();a++)
{
SdrMark* pMark = aMark.GetMark(a);
SdrObject* pObj = pMark->GetObj();
ImpCreate3DObject(pScene, pObj, bExtrude, fDepth, aLatheMat);
}
if(pScene->GetSubList() && pScene->GetSubList()->GetObjCount() != 0)
{
// Alle angelegten Objekte Tiefenarrangieren
if(bExtrude)
DoDepthArrange(pScene, fDepth);
// 3D-Objekte auf die Mitte des Gesamtrechtecks zentrieren
Vector3D aCenter = pScene->GetCenter();
Matrix4D aMatrix;
aMatrix.Translate(-aCenter);
pScene->SetTransform(pScene->GetTransform() * aMatrix);
// Szene initialisieren
pScene->NbcSetSnapRect(aRect);
Volume3D aBoundVol = pScene->GetBoundVolume();
InitScene(pScene, (double)aRect.GetWidth(),
(double)aRect.GetHeight(), aBoundVol.GetDepth());
// Transformationen initialisieren, damit bei RecalcSnapRect()
// richtig gerechnet wird
pScene->InitTransformationSet();
// Szene anstelle des ersten selektierten Objektes einfuegen
// und alle alten Objekte weghauen
SdrObject* pRepObj = aMark.GetMark(0)->GetObj();
SdrPageView* pPV = aMark.GetMark(0)->GetPageView();
MarkObj(pRepObj, pPV, TRUE);
ReplaceObject(pRepObj, *pPV, pScene, FALSE);
DeleteMarked();
MarkObj(pScene, pPV);
// Rotationskoerper um Rotationsachse drehen
if(!bExtrude && fRot3D != 0.0)
{
pScene->RotateZ(fRot3D);
}
// Default-Rotation setzen
double XRotateDefault = 20;
pScene->RotateX(DEG2RAD(XRotateDefault));
pScene->SetSortingMode(E3D_SORT_FAST_SORTING|E3D_SORT_IN_PARENTS|E3D_SORT_TEST_LENGTH);
// SnapRects der Objekte ungueltig
pScene->CorrectSceneDimensions();
pScene->SetSnapRect(aRect);
}
else
{
// Es wurden keine 3D Objekte erzeugt, schmeiss alles weg
delete pScene;
}
// Undo abschliessen
EndUndo();
}
}
/*************************************************************************
|*
|* Alle enthaltenen Extrude-Objekte Tiefenarrangieren
|*
\************************************************************************/
struct E3dDepthNeighbour
{
E3dDepthNeighbour* pNext;
E3dExtrudeObj* pObj;
E3dDepthNeighbour() { pNext = NULL; pObj = NULL; }
};
struct E3dDepthLayer
{
E3dDepthLayer* pDown;
E3dDepthNeighbour* pNext;
E3dDepthLayer() { pDown = NULL; pNext = NULL; }
~E3dDepthLayer() { while(pNext) { E3dDepthNeighbour* pSucc = pNext->pNext; delete pNext; pNext = pSucc; }}
};
void E3dView::DoDepthArrange(E3dScene* pScene, double fDepth)
{
if(pScene && pScene->GetSubList() && pScene->GetSubList()->GetObjCount() > 1)
{
SdrObjList* pSubList = pScene->GetSubList();
SdrObjListIter aIter(*pSubList, IM_FLAT);
E3dDepthLayer* pBaseLayer = NULL;
E3dDepthLayer* pLayer = NULL;
INT32 nNumLayers = 0;
SfxItemPool& rPool = pMod->GetItemPool();
while(aIter.IsMore())
{
E3dObject* pSubObj = (E3dObject*)aIter.Next();
if(pSubObj && pSubObj->ISA(E3dExtrudeObj))
{
E3dExtrudeObj* pExtrudeObj = (E3dExtrudeObj*)pSubObj;
const PolyPolygon3D& rExtrudePoly = pExtrudeObj->GetExtrudePolygon();
const SfxItemSet& rLocalSet = pExtrudeObj->GetItemSet();
XFillStyle eLocalFillStyle = ITEMVALUE(rLocalSet, XATTR_FILLSTYLE, XFillStyleItem);
Color aLocalColor = ((const XFillColorItem&)(rLocalSet.Get(XATTR_FILLCOLOR))).GetValue();
// ExtrudeObj einordnen
if(pLayer)
{
// Gibt es eine Ueberschneidung mit einem Objekt dieses
// Layers?
BOOL bOverlap(FALSE);
E3dDepthNeighbour* pAct = pLayer->pNext;
while(!bOverlap && pAct)
{
// ueberlappen sich pAct->pObj und pExtrudeObj ?
const PolyPolygon3D& rActPoly = pAct->pObj->GetExtrudePolygon();
bOverlap = rExtrudePoly.DoesOverlap(rActPoly, DEGREE_FLAG_X|DEGREE_FLAG_Y);
if(bOverlap)
{
// second ciriteria: is another fillstyle or color used?
const SfxItemSet& rCompareSet = pAct->pObj->GetItemSet();
XFillStyle eCompareFillStyle = ITEMVALUE(rCompareSet, XATTR_FILLSTYLE, XFillStyleItem);
if(eLocalFillStyle == eCompareFillStyle)
{
if(eLocalFillStyle == XFILL_SOLID)
{
Color aCompareColor = ((const XFillColorItem&)(rCompareSet.Get(XATTR_FILLCOLOR))).GetValue();
if(aCompareColor == aLocalColor)
{
bOverlap = FALSE;
}
}
else if(eLocalFillStyle == XFILL_NONE)
{
bOverlap = FALSE;
}
}
}
pAct = pAct->pNext;
}
if(bOverlap)
{
// ja, beginne einen neuen Layer
pLayer->pDown = new E3dDepthLayer;
pLayer = pLayer->pDown;
nNumLayers++;
pLayer->pNext = new E3dDepthNeighbour;
pLayer->pNext->pObj = pExtrudeObj;
}
else
{
// nein, Objekt kann in aktuellen Layer
E3dDepthNeighbour* pNewNext = new E3dDepthNeighbour;
pNewNext->pObj = pExtrudeObj;
pNewNext->pNext = pLayer->pNext;
pLayer->pNext = pNewNext;
}
}
else
{
// erster Layer ueberhaupt
pBaseLayer = new E3dDepthLayer;
pLayer = pBaseLayer;
nNumLayers++;
pLayer->pNext = new E3dDepthNeighbour;
pLayer->pNext->pObj = pExtrudeObj;
}
}
}
// Anzahl Layer steht fest
if(nNumLayers > 1)
{
// Arrangement ist notwendig
double fMinDepth = fDepth * 0.8;
double fStep = (fDepth - fMinDepth) / (double)nNumLayers;
pLayer = pBaseLayer;
while(pLayer)
{
// an pLayer entlangspazieren
E3dDepthNeighbour* pAct = pLayer->pNext;
while(pAct)
{
// Anpassen
pAct->pObj->SetItem(SfxUInt32Item(SDRATTR_3DOBJ_DEPTH, sal_uInt32(fMinDepth + 0.5)));
// Naechster Eintrag
pAct = pAct->pNext;
}
// naechster Layer
pLayer = pLayer->pDown;
fMinDepth += fStep;
}
}
// angelegte Strukturen aufraeumen
while(pBaseLayer)
{
pLayer = pBaseLayer->pDown;
delete pBaseLayer;
pBaseLayer = pLayer;
}
}
}
/*************************************************************************
|*
|* Drag beginnen, vorher ggf. Drag-Methode fuer 3D-Objekte erzeugen
|*
\************************************************************************/
BOOL E3dView::BegDragObj(const Point& rPnt, OutputDevice* pOut,
SdrHdl* pHdl, short nMinMov,
SdrDragMethod* pForcedMeth)
{
#ifndef SVX_LIGHT
if (b3dCreationActive && aMark.GetMarkCount())
{
// bestimme alle selektierten Polygone und gebe die gespiegelte Hilfsfigur aus
if (!pMirrorPolygon && !pMirroredPolygon)
{
CreateMirrorPolygons ();
ShowMirrorPolygons (aRef1, aRef2);
}
}
else
{
BOOL bOwnActionNecessary;
if (pHdl == NULL)
{
bOwnActionNecessary = TRUE;
}
else if (pHdl->IsVertexHdl() || pHdl->IsCornerHdl())
{
bOwnActionNecessary = TRUE;
}
else
{
bOwnActionNecessary = FALSE;
}
if(bOwnActionNecessary && aMark.GetMarkCount() >= 1)
{
E3dDragConstraint eConstraint = E3DDRAG_CONSTR_XYZ;
BOOL bThereAreRootScenes = FALSE;
BOOL bThereAre3DObjects = FALSE;
long nCnt = aMark.GetMarkCount();
for(long nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj)
{
if(pObj->ISA(E3dScene) && ((E3dScene*)pObj)->GetScene() == pObj)
bThereAreRootScenes = TRUE;
if(pObj->ISA(E3dObject))
bThereAre3DObjects = TRUE;
}
}
if( bThereAre3DObjects )
{
eDragHdl = ( pHdl == NULL ? HDL_MOVE : pHdl->GetKind() );
switch ( eDragMode )
{
case SDRDRAG_ROTATE:
case SDRDRAG_SHEAR:
{
switch ( eDragHdl )
{
case HDL_LEFT:
case HDL_RIGHT:
{
eConstraint = E3DDRAG_CONSTR_X;
}
break;
case HDL_UPPER:
case HDL_LOWER:
{
eConstraint = E3DDRAG_CONSTR_Y;
}
break;
case HDL_UPLFT:
case HDL_UPRGT:
case HDL_LWLFT:
case HDL_LWRGT:
{
eConstraint = E3DDRAG_CONSTR_Z;
}
break;
}
// die nicht erlaubten Rotationen ausmaskieren
eConstraint = E3dDragConstraint(eConstraint& eDragConstraint);
pForcedMeth = new E3dDragRotate(*this, aMark, eDragDetail, eConstraint,
SvtOptions3D().IsShowFull() );
}
break;
case SDRDRAG_MOVE:
{
if(!bThereAreRootScenes)
{
pForcedMeth = new E3dDragMove(*this, aMark, eDragDetail, eDragHdl, eConstraint,
SvtOptions3D().IsShowFull() );
}
}
break;
// spaeter mal
case SDRDRAG_MIRROR:
case SDRDRAG_CROOK:
case SDRDRAG_DISTORT:
case SDRDRAG_TRANSPARENCE:
case SDRDRAG_GRADIENT:
default:
{
long nCnt = aMark.GetMarkCount();
for(long nObjs = 0;nObjs < nCnt;nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dObject))
((E3dObject*) pObj)->SetDragDetail(eDragDetail);
}
}
break;
}
}
}
}
return SdrView::BegDragObj(rPnt, pOut, pHdl, nMinMov, pForcedMeth);
#else
return sal_False;
#endif
}
/*************************************************************************
|*
|* Pruefen, obj 3D-Szene markiert ist
|*
\************************************************************************/
BOOL E3dView::HasMarkedScene()
{
return (GetMarkedScene() != NULL);
}
/*************************************************************************
|*
|* Pruefen, obj 3D-Szene markiert ist
|*
\************************************************************************/
E3dScene* E3dView::GetMarkedScene()
{
ULONG nCnt = aMark.GetMarkCount();
for ( ULONG i = 0; i < nCnt; i++ )
if ( aMark.GetMark(i)->GetObj()->ISA(E3dScene) )
return (E3dScene*) aMark.GetMark(i)->GetObj();
return NULL;
}
/*************************************************************************
|*
|* aktuelles 3D-Zeichenobjekt setzen, dafuer Szene erzeugen
|*
\************************************************************************/
void E3dView::SetCurrent3DObj(E3dObject* p3DObj)
{
DBG_ASSERT(p3DObj != NULL, "Nana, wer steckt denn hier 'nen NULL-Zeiger rein?");
E3dScene* pScene = NULL;
// get transformed BoundVolume of the object
Volume3D aVolume;
const Volume3D& rObjVol = p3DObj->GetBoundVolume();
const Matrix4D& rObjTrans = p3DObj->GetTransform();
aVolume.Union(rObjVol.GetTransformVolume(rObjTrans));
double fW = aVolume.GetWidth();
double fH = aVolume.GetHeight();
Rectangle aRect(0,0, (long) fW, (long) fH);
pScene = new E3dPolyScene(Get3DDefaultAttributes());
InitScene(pScene, fW, fH, aVolume.MaxVec().Z() + ((fW + fH) / 4.0));
pScene->Insert3DObj(p3DObj);
pScene->NbcSetSnapRect(aRect);
SetCurrentLibObj(pScene);
}
/*************************************************************************
|*
|* neu erzeugte Szene initialisieren
|*
\************************************************************************/
void E3dView::InitScene(E3dScene* pScene, double fW, double fH, double fCamZ)
{
Camera3D aCam(pScene->GetCamera());
aCam.SetAutoAdjustProjection(FALSE);
aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
Vector3D aLookAt;
double fDefaultCamPosZ = GetDefaultCamPosZ();
Vector3D aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ);
aCam.SetPosAndLookAt(aCamPos, aLookAt);
aCam.SetFocalLength(GetDefaultCamFocal());
aCam.SetDefaults(Vector3D(0.0, 0.0, fDefaultCamPosZ), aLookAt, GetDefaultCamFocal());
pScene->SetCamera(aCam);
}
/*************************************************************************
|*
|* startsequenz fuer die erstellung eines 3D-Rotationskoerpers
|*
\************************************************************************/
void E3dView::Start3DCreation ()
{
b3dCreationActive = TRUE;
if (aMark.GetMarkCount())
{
// irgendwelche Markierungen ermitteln und ausschalten
BOOL bVis = IsMarkHdlShown();
if (bVis) HideMarkHdl(NULL);
// bestimme die koordinaten fuer JOEs Mirrorachse
// entgegen der normalen Achse wird diese an die linke Seite des Objektes
// positioniert
long nOutMin = 0;
long nOutMax = 0;
long nMinLen = 0;
long nObjDst = 0;
long nOutHgt = 0;
OutputDevice* pOut = GetWin(0);
// erstmal Darstellungsgrenzen bestimmen
if (pOut != NULL)
{
nMinLen = pOut->PixelToLogic(Size(0,50)).Height();
nObjDst = pOut->PixelToLogic(Size(0,20)).Height();
long nDst = pOut->PixelToLogic(Size(0,10)).Height();
nOutMin = -pOut->GetMapMode().GetOrigin().Y();
nOutMax = pOut->GetOutputSize().Height() - 1 + nOutMin;
nOutMin += nDst;
nOutMax -= nDst;
if (nOutMax - nOutMin < nDst)
{
nOutMin += nOutMax + 1;
nOutMin /= 2;
nOutMin -= (nDst + 1) / 2;
nOutMax = nOutMin + nDst;
}
nOutHgt = nOutMax - nOutMin;
long nTemp = nOutHgt / 4;
if (nTemp > nMinLen) nMinLen = nTemp;
}
// und dann die Markierungen oben und unten an das Objekt heften
Rectangle aR;
for(UINT32 nMark = 0; nMark < aMark.GetMarkCount(); nMark++)
{
XPolyPolygon aXPP;
SdrObject* pMark = aMark.GetMark(nMark)->GetObj();
pMark->TakeXorPoly(aXPP, FALSE);
aR.Union(aXPP.GetBoundRect());
}
Point aCenter(aR.Center());
long nMarkHgt = aR.GetHeight() - 1;
long nHgt = nMarkHgt + nObjDst * 2;
if (nHgt < nMinLen) nHgt = nMinLen;
long nY1 = aCenter.Y() - (nHgt + 1) / 2;
long nY2 = nY1 + nHgt;
if (pOut && (nMinLen > nOutHgt)) nMinLen = nOutHgt;
if (pOut)
{
if (nY1 < nOutMin)
{
nY1 = nOutMin;
if (nY2 < nY1 + nMinLen) nY2 = nY1 + nMinLen;
}
if (nY2 > nOutMax)
{
nY2 = nOutMax;
if (nY1 > nY2 - nMinLen) nY1 = nY2 - nMinLen;
}
}
aRef1.X() = aR.Left(); // Initial Achse um 2/100mm nach links
aRef1.Y() = nY1;
aRef2.X() = aRef1.X();
aRef2.Y() = nY2;
// Markierungen einschalten
SetMarkHandles();
if (bVis) ShowMarkHdl(NULL);
if (HasMarkedObj()) MarkListHasChanged();
// SpiegelPolygone SOFORT zeigen
CreateMirrorPolygons ();
const SdrHdlList &aHdlList = GetHdlList ();
ShowMirrorPolygons (aHdlList.GetHdl (HDL_REF1)->GetPos (),
aHdlList.GetHdl (HDL_REF2)->GetPos ());
}
}
/*************************************************************************
|*
|* was passiert bei einer Mausbewegung, wenn das Objekt erstellt wird ?
|*
\************************************************************************/
void E3dView::MovAction(const Point& rPnt)
{
if (b3dCreationActive)
{
SdrHdl* pHdl = GetDragHdl();
if (pHdl)
{
SdrHdlKind eHdlKind = pHdl->GetKind();
// reagiere nur bei einer spiegelachse
if ((eHdlKind == HDL_REF1) ||
(eHdlKind == HDL_REF2) ||
(eHdlKind == HDL_MIRX))
{
const SdrHdlList &aHdlList = GetHdlList ();
// loesche das gespiegelte Polygon, spiegele das Original und zeichne es neu
b3dCreationActive = FALSE; // Damit in DrawDragObj() gezeichnet wird
b3dCreationActive = TRUE; // restaurieren (Trick)
ShowMirrored ();
SdrView::MovAction (rPnt);
ShowMirrorPolygons (aHdlList.GetHdl (HDL_REF1)->GetPos (),
aHdlList.GetHdl (HDL_REF2)->GetPos ());
}
}
else
{
SdrView::MovAction (rPnt);
}
}
else
{
SdrView::MovAction (rPnt);
}
}
/*************************************************************************
|*
|* Schluss. Objekt und evtl. Unterobjekte ueber ImpCreate3DLathe erstellen
|* [FG] Mit dem Parameterwert TRUE (SDefault: FALSE) wird einfach ein
|* Rotationskoerper erzeugt, ohne den Benutzer die Lage der
|* Achse fetlegen zu lassen. Es reicht dieser Aufruf, falls
|* ein Objekt selektiert ist. (keine Initialisierung noetig)
|*
\************************************************************************/
void E3dView::End3DCreation(BOOL bUseDefaultValuesForMirrorAxes)
{
if(HasMarkedObj())
{
if(bUseDefaultValuesForMirrorAxes)
{
Rectangle aRect = GetAllMarkedRect();
if(aRect.GetWidth() <= 1)
aRect.SetSize(Size(500, aRect.GetHeight()));
if(aRect.GetHeight() <= 1)
aRect.SetSize(Size(aRect.GetWidth(), 500));
Vector3D aPnt1(aRect.Left(), -aRect.Top(), 0.0);
Vector3D aPnt2(aRect.Left(), -aRect.Bottom(), 0.0);
ConvertMarkedObjTo3D(FALSE, aPnt1, aPnt2);
}
else
{
// Hilfsfigur ausschalten
ShowMirrored();
// irgendwo kassieren wir eine Rekursion, also unterbinden
b3dCreationActive = FALSE;
// bestimme aus den Handlepositionen und den Versatz der Punkte
const SdrHdlList &aHdlList = GetHdlList();
Point aMirrorRef1 = aHdlList.GetHdl(HDL_REF1)->GetPos();
Point aMirrorRef2 = aHdlList.GetHdl(HDL_REF2)->GetPos();
Vector3D aPnt1(aMirrorRef1.X(), -aMirrorRef1.Y(), 0.0);
Vector3D aPnt2(aMirrorRef2.X(), -aMirrorRef2.Y(), 0.0);
ConvertMarkedObjTo3D(FALSE, aPnt1, aPnt2);
}
}
ResetCreationActive();
}
/*************************************************************************
|*
|* stelle das Mirrorobjekt dar
|*
\************************************************************************/
void E3dView::ShowMirrored ()
{
if (b3dCreationActive)
{
OutputDevice *pOut = GetWin(0);
RasterOp eRop0 = pOut->GetRasterOp();
Color aOldLineColor( pXOut->GetLineColor() );
Color aOldFillColor( pXOut->GetFillColor() );
Color aNewLineColor( COL_BLACK );
Color aNewFillColor( COL_TRANSPARENT );
// invertiere die Darstellung
pOut->SetRasterOp(ROP_INVERT);
pXOut->SetOutDev(pOut);
pXOut->OverrideLineColor( aNewLineColor );
pXOut->OverrideFillColor( aNewFillColor );
for (long nMark = 0;
nMark < nPolyCnt;
nMark ++)
{
const XPolyPolygon &rXPP = pMirroredPolygon [nMark];
USHORT nPolyAnz = rXPP.Count();
for (USHORT nPolyNum = 0;
nPolyNum < nPolyAnz;
nPolyNum ++)
{
const XPolygon &rXP = rXPP [nPolyNum];
pXOut->DrawXPolyLine(rXP);
}
}
pXOut->OverrideLineColor( aOldLineColor );
pXOut->OverrideFillColor( aOldFillColor );
pOut->SetRasterOp(eRop0);
}
}
/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/
E3dView::~E3dView ()
{
__DELETE(nPolyCnt) pMirrorPolygon;
__DELETE(nPolyCnt) pMirroredPolygon;
__DELETE(nPolyCnt) pMarkedObjs;
}
/*************************************************************************
|*
|* Bestimme Anzahl der Polygone und kopiere in die Spiegelpolygone
|*
\************************************************************************/
void E3dView::CreateMirrorPolygons ()
{
nPolyCnt = aMark.GetMarkCount();
pMirrorPolygon = new XPolyPolygon [nPolyCnt];
pMirroredPolygon = new XPolyPolygon [nPolyCnt];
pMarkedObjs = new SdrObject* [nPolyCnt];
pMyPV = aMark.GetMark(0)->GetPageView();
for (long nMark = nPolyCnt;
nMark > 0;
)
{
SdrMark *pMark = aMark.GetMark(-- nMark);
SdrObject *pObj = pMark->GetObj();
pObj->TakeXorPoly (pMirrorPolygon [nMark], FALSE);
pMarkedObjs [nMark] = pObj;
}
}
/*************************************************************************
|*
|* spiegele die originalpolygone und stelle sie als hilfsfigur dar
|*
\************************************************************************/
void E3dView::ShowMirrorPolygons (Point aMirrorPoint1,
Point aMirrorPoint2)
{
for (long nMark = 0;
nMark < nPolyCnt;
nMark ++)
{
pMirroredPolygon [nMark] = pMirrorPolygon [nMark];
MirrorXPoly(pMirroredPolygon [nMark], aMirrorPoint1, aMirrorPoint2);
}
if (nPolyCnt) ShowMirrored ();
}
/*************************************************************************
|*
|* beende das erzeugen und loesche die polygone
|*
\************************************************************************/
void E3dView::ResetCreationActive ()
{
__DELETE(nPolyCnt) pMirrorPolygon;
__DELETE(nPolyCnt) pMirroredPolygon;
__DELETE(nPolyCnt) pMarkedObjs;
pMarkedObjs = 0;
pMirrorPolygon =
pMirroredPolygon = 0;
b3dCreationActive = FALSE;
nPolyCnt = 0;
}
/*************************************************************************
|*
|* Skalarprodukt zweier Punktvektoren
|*
\************************************************************************/
long Scalar (Point aPoint1,
Point aPoint2)
{
return aPoint1.X () * aPoint2.X () + aPoint1.Y () * aPoint2.Y ();
}
/*************************************************************************
|*
|* Skalarprodukt zweier Punktvektoren
|*
\************************************************************************/
Point ScaleVector (Point aPoint,
double nScale)
{
return Point ((long) ((double) aPoint.X () * nScale), (long) ((double) aPoint.Y () * nScale));
}
/*************************************************************************
|*
|* Skalarprodukt zweier Punktvektoren
|*
\************************************************************************/
double NormVector (Point aPoint)
{
return sqrt ((double) Scalar (aPoint, aPoint));
}
/*************************************************************************
|*
|* Pruefe, ob sich zwei Geradensegemente schneiden
|* Dazu wird ueber einfache Determinanten bestimmt, wie die Endpunkte
|* zu der jeweils anderen Gerade liegen.
|*
\************************************************************************/
BOOL LineCutting (Point aP1,
Point aP2,
Point aP3,
Point aP4)
{
long nS1 = Point2Line (aP1, aP3, aP4);
long nS2 = Point2Line (aP2, aP3, aP4);
long nS3 = Point2Line (aP3, aP1, aP2);
long nS4 = Point2Line (aP4, aP1, aP2);
// die werte koennen reichlich gross werden, also geht eine multiplikation daneben
BOOL bCut (((nS1 < 0) && (nS2 > 0) || (nS1 > 0) && (nS2 < 0)) &&
((nS3 < 0) && (nS4 > 0) || (nS3 > 0) && (nS4 < 0)));
if (bCut)
{
BOOL bStop = bCut;
}
return ((nS1 < 0) && (nS2 > 0) || (nS1 > 0) && (nS2 < 0)) &&
((nS3 < 0) && (nS4 > 0) || (nS3 > 0) && (nS4 < 0));
}
/*************************************************************************
|*
|* Bestimme, ob sich ein Punkt aP1 rechts oder links eines Geradensegments,
|* definiert durch aP2 und aP3, befindet.
|* >0 : rechts, <0 : links, =0 : auf dem Geradensegment
|* Die Vektoren (Punkte) liegen in der homogenen Form vor, wobei die
|* Skalierung =1 gesetzt ist (schneller und einfacher).
|*
\************************************************************************/
long Point2Line (Point aP1,
Point aP2,
Point aP3)
{
return (aP2.X () * aP3.Y () - aP2.Y () * aP3.X ()) -
(aP1.X () * aP3.Y () - aP1.Y () * aP3.X ()) +
(aP1.X () * aP2.Y () - aP1.Y () * aP2.X ());
}
/*************************************************************************
|*
|* Bestimme den Abstand eines Punktes u zu einem Geradensegment,
|* definiert durch v1 und v.
|*
\************************************************************************/
long DistPoint2Line (Point u,
Point v1,
Point v)
{
Point w = v1 - v;
return (long) NormVector (v - ScaleVector (w, (double) Scalar (v - u, w) / (double) Scalar (w, w)) - u);
}
/*************************************************************************
|*
|* Klasse initialisieren
|*
\************************************************************************/
void E3dView::InitView ()
{
eDragConstraint = E3DDRAG_CONSTR_XYZ;
eDragDetail = E3DDETAIL_ONEBOX;
b3dCreationActive = FALSE;
pMirrorPolygon = 0;
pMirroredPolygon = 0;
nPolyCnt = 0;
pMyPV = 0;
pMarkedObjs = 0;
fDefaultScaleX =
fDefaultScaleY =
fDefaultScaleZ = 1.0;
fDefaultRotateX =
fDefaultRotateY =
fDefaultRotateZ = 0.0;
fDefaultExtrusionDeepth = 1000; // old: 2000;
fDefaultLightIntensity = 0.8; // old: 0.6;
fDefaultAmbientIntensity = 0.4;
nHDefaultSegments = 12;
nVDefaultSegments = 12;
aDefaultLightColor = RGB_Color(COL_WHITE);
aDefaultAmbientColor = RGB_Color(COL_BLACK);
aDefaultLightPos = Vector3D (1, 1, 1); // old: Vector3D (0, 0, 1);
aDefaultLightPos.Normalize();
bDoubleSided = FALSE;
}
/*************************************************************************
|*
|* Zeige eine Hilfsfigur
|*
\************************************************************************/
void E3dView::ShowDragObj (OutputDevice *pOut)
{
SdrView::ShowDragObj (pOut);
}
/*************************************************************************
|*
|* Verdecke eine Hilfsfigur
|*
\************************************************************************/
void E3dView::HideDragObj (OutputDevice *pOut)
{
SdrView::HideDragObj (pOut);
}
/*************************************************************************
|*
|* Zeige eine Hilfsfigur
|*
\************************************************************************/
void E3dView::DrawDragObj (OutputDevice *pOut,
BOOL bFull) const
{
if (!b3dCreationActive)
{
SdrView::DrawDragObj (pOut, bFull);
}
}
/*************************************************************************
|*
|* Koennen die selektierten Objekte aufgebrochen werden?
|*
\************************************************************************/
BOOL E3dView::IsBreak3DObjPossible() const
{
ULONG nCount = aMark.GetMarkCount();
if (nCount > 0)
{
ULONG i = 0;
while (i < nCount)
{
SdrObject* pObj = aMark.GetMark(i)->GetObj();
if (pObj && pObj->ISA(E3dObject))
{
if(!(((E3dObject*)pObj)->IsBreakObjPossible()))
return FALSE;
}
else
{
return FALSE;
}
i++;
}
}
else
{
return FALSE;
}
return TRUE;
}
/*************************************************************************
|*
|* Selektierte Lathe-Objekte aufbrechen
|*
\************************************************************************/
void E3dView::Break3DObj()
{
if(IsBreak3DObjPossible())
{
// ALLE selektierten Objekte werden gewandelt
UINT32 nCount = aMark.GetMarkCount();
BegUndo(String(SVX_RESSTR(RID_SVX_3D_UNDO_BREAK_LATHE)));
for(UINT32 a=0;a<nCount;a++)
{
E3dObject* pObj = (E3dObject*)aMark.GetMark(a)->GetObj();
BreakSingle3DObj(pObj);
}
DeleteMarked();
EndUndo();
}
}
void E3dView::BreakSingle3DObj(E3dObject* pObj)
{
if(pObj->ISA(E3dScene))
{
SdrObjList* pSubList = pObj->GetSubList();
SdrObjListIter aIter(*pSubList, IM_FLAT);
while(aIter.IsMore())
{
E3dObject* pSubObj = (E3dObject*)aIter.Next();
BreakSingle3DObj(pSubObj);
}
}
else
{
SdrAttrObj* pNewObj = pObj->GetBreakObj();
if(pNewObj)
{
InsertObject(pNewObj, *GetPageViewPvNum(0), SDRINSERT_DONTMARK);
pNewObj->SendRepaintBroadcast();
}
}
}
/*************************************************************************
|*
|* Szenen mischen
|*
\************************************************************************/
// Wird bisher noch nirgenswo (weder im Draw oder Chart) aufgerufen
void E3dView::MergeScenes ()
{
ULONG nCount = aMark.GetMarkCount();
if (nCount > 0)
{
ULONG nObj = 0;
SdrObject *pObj = aMark.GetMark(nObj)->GetObj();
E3dScene *pScene = new E3dPolyScene(Get3DDefaultAttributes());
Volume3D aBoundVol;
Rectangle aAllBoundRect (GetMarkedObjBoundRect ());
Point aCenter (aAllBoundRect.Center());
while (pObj)
{
if (pObj->ISA(E3dScene))
{
/**********************************************************
* Es ist eine 3D-Scene oder 3D-PolyScene
**********************************************************/
SdrObjList* pSubList = ((E3dObject*) pObj)->GetSubList();
SdrObjListIter aIter(*pSubList, IM_FLAT);
while (aIter.IsMore())
{
/******************************************************
* LatheObjekte suchen
******************************************************/
SdrObject* pSubObj = aIter.Next();
if (!pSubObj->ISA(E3dLight))
{
E3dObject *pNewObj = 0;
switch (pSubObj->GetObjIdentifier())
{
case E3D_OBJECT_ID:
pNewObj = new E3dObject;
*(E3dObject*)pNewObj = *(E3dObject*)pSubObj;
break;
case E3D_POLYOBJ_ID :
pNewObj = new E3dPolyObj;
*(E3dPolyObj*)pNewObj= *(E3dPolyObj*)pSubObj;
break;
case E3D_CUBEOBJ_ID :
pNewObj = new E3dCubeObj;
*(E3dCubeObj*)pNewObj = *(E3dCubeObj*)pSubObj;
break;
case E3D_SPHEREOBJ_ID:
pNewObj = new E3dSphereObj;
*(E3dSphereObj*)pNewObj = *(E3dSphereObj*)pSubObj;
break;
case E3D_POINTOBJ_ID:
pNewObj = new E3dPointObj;
*(E3dPointObj*)pNewObj = *(E3dPointObj*)pSubObj;
break;
case E3D_EXTRUDEOBJ_ID:
pNewObj = new E3dExtrudeObj;
*(E3dExtrudeObj*)pNewObj = *(E3dExtrudeObj*)pSubObj;
break;
case E3D_LATHEOBJ_ID:
pNewObj = new E3dLatheObj;
*(E3dLatheObj*)pNewObj = *(E3dLatheObj*)pSubObj;
break;
case E3D_LABELOBJ_ID:
pNewObj = new E3dLabelObj;
*(E3dLabelObj*)pNewObj = *(E3dLabelObj*)pSubObj;
break;
case E3D_COMPOUNDOBJ_ID:
pNewObj = new E3dCompoundObject;
*(E3dCompoundObject*)pNewObj = *(E3dCompoundObject*)pSubObj;
break;
}
Rectangle aBoundRect = pSubObj->GetBoundRect ();
Matrix4D aMatrix;
aMatrix.Translate(Vector3D(aBoundRect.Left () - aCenter.X (), aCenter.Y(), 0));
pNewObj->SetTransform(pNewObj->GetTransform() * aMatrix);
if (pNewObj) aBoundVol.Union (pNewObj->GetBoundVolume());
pScene->Insert3DObj (pNewObj);
}
}
}
nObj++;
if (nObj < nCount)
{
pObj = aMark.GetMark(nObj)->GetObj();
}
else
{
pObj = NULL;
}
}
double fW = aAllBoundRect.GetWidth();
double fH = aAllBoundRect.GetHeight();
Rectangle aRect(0,0, (long) fW, (long) fH);
InitScene(pScene, fW, fH, aBoundVol.MaxVec().Z() + + ((fW + fH) / 4.0));
pScene->FitSnapRectToBoundVol();
pScene->NbcSetSnapRect(aRect);
Camera3D &aCamera = (Camera3D&) pScene->GetCamera ();
Vector3D aMinVec (aBoundVol.MinVec ());
Vector3D aMaxVec (aBoundVol.MaxVec ());
double fDeepth = fabs (aMaxVec.Z () - aMinVec.Z ());
aCamera.SetPRP (Vector3D (0, 0, 1000));
double fDefaultCamPosZ = GetDefaultCamPosZ();
aCamera.SetPosition (Vector3D(0.0, 0.0, fDefaultCamPosZ + fDeepth / 2));
aCamera.SetFocalLength(GetDefaultCamFocal());
pScene->SetCamera (aCamera);
// SnapRects der Objekte ungueltig
pScene->SetRectsDirty();
// Transformationen initialisieren, damit bei RecalcSnapRect()
// richtig gerechnet wird
pScene->InitTransformationSet();
InsertObject (pScene, *(aMark.GetMark(0)->GetPageView()));
// SnapRects der Objekte ungueltig
pScene->SetRectsDirty();
}
}
/*************************************************************************
|*
|* Possibilities, hauptsaechlich gruppieren/ungruppieren
|*
\************************************************************************/
void E3dView::CheckPossibilities()
{
// call parent
SdrView::CheckPossibilities();
// Weitere Flags bewerten
if(bGroupPossible || bUnGroupPossible || bGrpEnterPossible)
{
INT32 nMarkCnt = aMark.GetMarkCount();
BOOL bCoumpound = FALSE;
BOOL b3DObject = FALSE;
for(INT32 nObjs = 0L; (nObjs < nMarkCnt) && !bCoumpound; nObjs++)
{
SdrObject *pObj = aMark.GetMark(nObjs)->GetObj();
if(pObj && pObj->ISA(E3dCompoundObject))
bCoumpound = TRUE;
if(pObj && pObj->ISA(E3dObject))
b3DObject = TRUE;
}
// Bisher: Es sind ZWEI oder mehr beliebiger Objekte selektiert.
// Nachsehen, ob CompoundObjects beteiligt sind. Falls ja,
// das Gruppieren verbieten.
if(bGroupPossible && bCoumpound)
bGroupPossible = FALSE;
if(bUnGroupPossible && b3DObject)
bUnGroupPossible = FALSE;
if(bGrpEnterPossible && bCoumpound)
bGrpEnterPossible = FALSE;
}
// bGroupPossible
// bCombinePossible
// bUnGroupPossible
// bGrpEnterPossible
}
|