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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
#include <ShapeFactory.hxx>
#include <VDiagram.hxx>
#include <Diagram.hxx>
#include <PropertyMapper.hxx>
#include <ViewDefines.hxx>
#include <Stripe.hxx>
#include <ObjectIdentifier.hxx>
#include <DiagramHelper.hxx>
#include <ChartType.hxx>
#include <BaseGFXHelper.hxx>
#include <ChartTypeHelper.hxx>
#include <ThreeDHelper.hxx>
#include <defines.hxx>
#include <editeng/unoprnms.hxx>
#include <svx/scene3d.hxx>
#include <svx/e3dsceneupdater.hxx>
#include <tools/diagnose_ex.h>
namespace chart
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2;
VDiagram::VDiagram(
const rtl::Reference<Diagram> & xDiagram, const drawing::Direction3D& rPreferredAspectRatio,
sal_Int32 nDimension )
: m_nDimensionCount(nDimension)
, m_xDiagram(xDiagram)
, m_aPreferredAspectRatio(rPreferredAspectRatio)
, m_fXAnglePi(0)
, m_fYAnglePi(0)
, m_fZAnglePi(0)
, m_bRightAngledAxes(false)
{
if( m_nDimensionCount != 3)
return;
ThreeDHelper::getRotationAngleFromDiagram( xDiagram, m_fXAnglePi, m_fYAnglePi, m_fZAnglePi );
if( ChartTypeHelper::isSupportingRightAngledAxes(
DiagramHelper::getChartTypeByIndex( m_xDiagram, 0 ) ) )
{
if(xDiagram.is())
xDiagram->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes;
if( m_bRightAngledAxes )
{
ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fXAnglePi, m_fYAnglePi );
m_fZAnglePi=0.0;
}
}
}
VDiagram::~VDiagram()
{
}
void VDiagram::init( const rtl::Reference<SvxShapeGroupAnyD>& xTarget )
{
m_xTarget = xTarget;
}
void VDiagram::createShapes( const awt::Point& rPos, const awt::Size& rSize )
{
m_aAvailablePosIncludingAxes = rPos;
m_aAvailableSizeIncludingAxes = rSize;
if( m_nDimensionCount == 3 )
createShapes_3d();
else
createShapes_2d();
}
::basegfx::B2IRectangle VDiagram::adjustPosAndSize( const awt::Point& rPos, const awt::Size& rSize )
{
::basegfx::B2IRectangle aAllowedRect( BaseGFXHelper::makeRectangle(m_aAvailablePosIncludingAxes,m_aAvailableSizeIncludingAxes) );
::basegfx::B2IRectangle aNewInnerRect( BaseGFXHelper::makeRectangle(rPos,rSize) );
aNewInnerRect.intersect( aAllowedRect );
if( m_nDimensionCount == 3 )
aNewInnerRect = adjustPosAndSize_3d( BaseGFXHelper::B2IRectangleToAWTPoint(aNewInnerRect), BaseGFXHelper::B2IRectangleToAWTSize(aNewInnerRect) );
else
aNewInnerRect = adjustPosAndSize_2d( BaseGFXHelper::B2IRectangleToAWTPoint(aNewInnerRect), BaseGFXHelper::B2IRectangleToAWTSize(aNewInnerRect) );
return aNewInnerRect;
}
::basegfx::B2IRectangle VDiagram::adjustPosAndSize_2d( const awt::Point& rPos, const awt::Size& rAvailableSize )
{
m_aCurrentPosWithoutAxes = rPos;
m_aCurrentSizeWithoutAxes = rAvailableSize;
if( m_aPreferredAspectRatio.DirectionX > 0 && m_aPreferredAspectRatio.DirectionY > 0)
{
//do not change aspect ratio
awt::Size aAspectRatio( static_cast<sal_Int32>(m_aPreferredAspectRatio.DirectionX*FIXED_SIZE_FOR_3D_CHART_VOLUME),
static_cast<sal_Int32>(m_aPreferredAspectRatio.DirectionY*FIXED_SIZE_FOR_3D_CHART_VOLUME ));
m_aCurrentSizeWithoutAxes = ShapeFactory::calculateNewSizeRespectingAspectRatio(
rAvailableSize, aAspectRatio );
//center diagram position
m_aCurrentPosWithoutAxes = ShapeFactory::calculateTopLeftPositionToCenterObject(
rPos, rAvailableSize, m_aCurrentSizeWithoutAxes );
}
if( m_xWall2D.is() )
{
m_xWall2D->setSize( m_aCurrentSizeWithoutAxes);
m_xWall2D->setPosition(m_aCurrentPosWithoutAxes);
}
return BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes);
}
void VDiagram::createShapes_2d()
{
OSL_PRECOND(m_xTarget.is(), "is not proper initialized");
if (!m_xTarget.is())
return;
//create group shape
rtl::Reference<SvxShapeGroupAnyD> xOuterGroup_Shapes = ShapeFactory::createGroup2D(m_xTarget);
m_xOuterGroupShape = xOuterGroup_Shapes;
rtl::Reference<SvxShapeGroupAnyD> xGroupForWall( ShapeFactory::createGroup2D(xOuterGroup_Shapes,"PlotAreaExcludingAxes") );
//create independent group shape as container for datapoints and such things
m_xCoordinateRegionShape = ShapeFactory::createGroup2D(xOuterGroup_Shapes,"testonly;CooContainer=XXX_CID");
bool bAddFloorAndWall = DiagramHelper::isSupportingFloorAndWall( m_xDiagram );
//add back wall
{
m_xWall2D = ShapeFactory::createRectangle( xGroupForWall );
try
{
OSL_ENSURE( m_xDiagram.is(), "Invalid Diagram model" );
if( m_xDiagram.is() )
{
uno::Reference< beans::XPropertySet > xWallProp( m_xDiagram->getWall());
if( xWallProp.is())
PropertyMapper::setMappedProperties( *m_xWall2D, xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
}
if( !bAddFloorAndWall )
{
//we always need this object as dummy object for correct scene dimensions
//but it should not be visible in this case:
ShapeFactory::makeShapeInvisible( m_xWall2D );
}
else
{
//CID for selection handling
OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ) );//@todo read CID from model
m_xWall2D->SvxShape::setPropertyValue( UNO_NAME_MISC_OBJ_NAME, uno::Any( aWallCID ) );
}
}
catch( const uno::Exception& )
{
TOOLS_WARN_EXCEPTION("chart2", "" );
}
}
//position and size for diagram
adjustPosAndSize_2d( m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes );
}
static E3dScene* lcl_getE3dScene( const rtl::Reference<SvxShapeGroupAnyD>& xShape )
{
return dynamic_cast< E3dScene* >(xShape->GetSdrObject());
}
static void lcl_setLightSources(
const uno::Reference< beans::XPropertySet > & xSource,
const uno::Reference< beans::XPropertySet > & xDest )
{
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_1,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_1));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_3,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_3));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_4,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_4));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_5,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_5));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_6,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_6));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_7,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_7));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_8,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_8));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_1,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_1));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_3,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_3));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_4,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_4));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_5,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_5));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_6,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_6));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_7,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_7));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_8,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_8));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_1,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_1));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_3,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_3));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_4,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_4));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_5,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_5));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_6,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_6));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_7,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_7));
xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_8,
xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_8));
}
namespace
{
void lcl_ensureScaleValue( double& rfScale )
{
OSL_ENSURE(rfScale>0, "calculation error for automatic 3D height in chart");
if( rfScale<0 )
rfScale = 1.0;
else if( rfScale<0.2 )
rfScale = 0.2;
else if( rfScale>5.0 )
rfScale = 5.0;
}
}
void VDiagram::adjustAspectRatio3d( const awt::Size& rAvailableSize )
{
OSL_PRECOND(m_xAspectRatio3D.is(), "created shape offers no XPropertySet");
if( !m_xAspectRatio3D.is())
return;
try
{
double fScaleX = m_aPreferredAspectRatio.DirectionX;
double fScaleY = m_aPreferredAspectRatio.DirectionY;
double fScaleZ = m_aPreferredAspectRatio.DirectionZ;
//normalize scale factors
{
double fMax = std::max( std::max( fScaleX, fScaleY) , fScaleZ );
fScaleX/=fMax;
fScaleY/=fMax;
fScaleZ/=fMax;
}
if( fScaleX<0 || fScaleY<0 || fScaleZ<0 )
{
//calculate automatic 3D aspect ratio that fits good into the given 2D area
double fW = rAvailableSize.Width;
double fH = rAvailableSize.Height;
double sx = fabs(sin(m_fXAnglePi));
double sy = fabs(sin(m_fYAnglePi));
double cz = fabs(cos(m_fZAnglePi));
double sz = fabs(sin(m_fZAnglePi));
if(m_bRightAngledAxes)
{
//base equations:
//fH*zoomfactor == sx*fScaleZ + fScaleY;
//fW*zoomfactor == sy*fScaleZ + fScaleX;
if( fScaleX>0 && fScaleZ>0 )
{
//calculate fScaleY:
if( !::basegfx::fTools::equalZero(fW) )
{
fScaleY = (fH/fW)*(sy*fScaleZ+fScaleX)-(sx*fScaleZ);
lcl_ensureScaleValue( fScaleY );
}
else
fScaleY = 1.0;//looking from top or bottom the height is irrelevant
}
else if( fScaleY>0 && fScaleZ>0 )
{
//calculate fScaleX:
if( !::basegfx::fTools::equalZero(fH) )
{
fScaleX = (fW/fH)*(sx*fScaleZ+fScaleY)-(sy*fScaleZ);
lcl_ensureScaleValue(fScaleX);
}
else
fScaleX = 1.0;//looking from top or bottom height is irrelevant
}
else
{
//todo
OSL_FAIL("not implemented yet");
if( fScaleX<0 )
fScaleX = 1.0;
if( fScaleY<0 )
fScaleY = 1.0;
if( fScaleZ<0 )
fScaleZ = 1.0;
}
}
else
{
//base equations:
//fH*zoomfactor == cz*fScaleY + sz*fScaleX;
//fW*zoomfactor == cz*fScaleX + sz*fScaleY;
//==> fScaleY*(fH*sz-fW*cz) == fScaleX*(fW*sz-fH*cz);
if( fScaleX>0 && fScaleZ>0 )
{
//calculate fScaleY:
double fDivide = fH*sz-fW*cz;
if( !::basegfx::fTools::equalZero(fDivide) )
{
fScaleY = fScaleX*(fW*sz-fH*cz) / fDivide;
lcl_ensureScaleValue(fScaleY);
}
else
fScaleY = 1.0;//looking from top or bottom the height is irrelevant
}
else if( fScaleY>0 && fScaleZ>0 )
{
//calculate fScaleX:
double fDivide = fW*sz-fH*cz;
if( !::basegfx::fTools::equalZero(fDivide) )
{
fScaleX = fScaleY*(fH*sz-fW*cz) / fDivide;
lcl_ensureScaleValue(fScaleX);
}
else
fScaleX = 1.0;//looking from top or bottom height is irrelevant
}
else
{
//todo
OSL_FAIL("not implemented yet");
if( fScaleX<0 )
fScaleX = 1.0;
if( fScaleY<0 )
fScaleY = 1.0;
if( fScaleZ<0 )
fScaleZ = 1.0;
}
}
}
//normalize scale factors
{
double fMax = std::max( std::max( fScaleX, fScaleY) , fScaleZ );
fScaleX/=fMax;
fScaleY/=fMax;
fScaleZ/=fMax;
}
// identity matrix
::basegfx::B3DHomMatrix aResult;
aResult.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
-FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
-FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
aResult.scale( fScaleX, fScaleY, fScaleZ );
aResult.translate( FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
// To get the 3D aspect ratio's effect on the 2D scene size, the scene's 2D size needs to be adapted to
// 3D content changes here. The tooling class remembers the current 3D transformation stack
// and in its destructor, calculates a new 2D SnapRect for the scene and it's modified 3D geometry.
E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));
m_xAspectRatio3D->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
, uno::Any(BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aResult )) );
}
catch( const uno::Exception& )
{
TOOLS_WARN_EXCEPTION("chart2", "" );
}
}
::basegfx::B2IRectangle VDiagram::adjustPosAndSize_3d( const awt::Point& rPos, const awt::Size& rAvailableSize )
{
adjustAspectRatio3d( rAvailableSize );
//do not change aspect ratio of 3D scene with 2D bound rect
m_aCurrentSizeWithoutAxes = ShapeFactory::calculateNewSizeRespectingAspectRatio(
rAvailableSize, m_xOuterGroupShape->getSize() );
m_xOuterGroupShape->setSize( m_aCurrentSizeWithoutAxes );
//center diagram position
m_aCurrentPosWithoutAxes= ShapeFactory::calculateTopLeftPositionToCenterObject(
rPos, rAvailableSize, m_aCurrentSizeWithoutAxes );
m_xOuterGroupShape->setPosition(m_aCurrentPosWithoutAxes);
return BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes);
}
void VDiagram::createShapes_3d()
{
OSL_PRECOND(m_xTarget.is(), "is not proper initialized");
if (!m_xTarget.is())
return;
//create shape
rtl::Reference<Svx3DSceneObject> xShapes = ShapeFactory::createGroup3D( m_xTarget, "PlotAreaExcludingAxes" );
m_xOuterGroupShape = xShapes;
rtl::Reference<SvxShapeGroupAnyD> xOuterGroup_Shapes = m_xOuterGroupShape;
//create additional group to manipulate the aspect ratio of the whole diagram:
xOuterGroup_Shapes = ShapeFactory::createGroup3D( xOuterGroup_Shapes );
m_xAspectRatio3D = xOuterGroup_Shapes;
bool bAddFloorAndWall = DiagramHelper::isSupportingFloorAndWall( m_xDiagram );
const bool bDoubleSided = false;
//add walls
{
uno::Reference< beans::XPropertySet > xWallProp;
if( m_xDiagram.is() )
xWallProp.set( m_xDiagram->getWall() );
OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ) );//@todo read CID from model
if( !bAddFloorAndWall )
aWallCID.clear();
rtl::Reference<Svx3DSceneObject> xWallGroup_Shapes = ShapeFactory::createGroup3D( xOuterGroup_Shapes, aWallCID );
CuboidPlanePosition eLeftWallPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardLeftWall( m_xDiagram ) );
CuboidPlanePosition eBackWallPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBackWall( m_xDiagram ) );
//add left wall
{
short nRotatedTexture = ( eBackWallPos==CuboidPlanePosition_Front ) ? 3 : 1;
double xPos = 0.0;
if( eLeftWallPos==CuboidPlanePosition_Right )
xPos = FIXED_SIZE_FOR_3D_CHART_VOLUME;
Stripe aStripe( drawing::Position3D(xPos,FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
, drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME)
, drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0) );
if( eLeftWallPos==CuboidPlanePosition_Right )
{
nRotatedTexture = ( eBackWallPos==CuboidPlanePosition_Front ) ? 2 : 0;
aStripe = Stripe( drawing::Position3D(xPos,FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
, drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
, drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME) );
}
aStripe.InvertNormal(true);
rtl::Reference<Svx3DPolygonObject> xShape =
ShapeFactory::createStripe( xWallGroup_Shapes, aStripe
, xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided, nRotatedTexture );
if( !bAddFloorAndWall )
{
//we always need this object as dummy object for correct scene dimensions
//but it should not be visible in this case:
ShapeFactory::makeShapeInvisible( xShape );
}
}
//add back wall
{
short nRotatedTexture = 0;
double zPos = 0.0;
if( eBackWallPos==CuboidPlanePosition_Front )
zPos = FIXED_SIZE_FOR_3D_CHART_VOLUME;
Stripe aStripe( drawing::Position3D(0,FIXED_SIZE_FOR_3D_CHART_VOLUME,zPos)
, drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
, drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0) );
if( eBackWallPos==CuboidPlanePosition_Front )
{
aStripe = Stripe( drawing::Position3D(0,FIXED_SIZE_FOR_3D_CHART_VOLUME,zPos)
, drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0)
, drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0) );
nRotatedTexture = 3;
}
aStripe.InvertNormal(true);
rtl::Reference<Svx3DPolygonObject> xShape =
ShapeFactory::createStripe(xWallGroup_Shapes, aStripe
, xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided, nRotatedTexture );
if( !bAddFloorAndWall )
{
//we always need this object as dummy object for correct scene dimensions
//but it should not be visible in this case:
ShapeFactory::makeShapeInvisible( xShape );
}
}
}
try
{
//perspective
{
//ignore distance and focal length from file format and model completely
//use vrp only to indicate the distance of the camera and thus influence the perspective
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_SCENE_DISTANCE, uno::Any(
static_cast<sal_Int32>(ThreeDHelper::getCameraDistance( m_xDiagram ))));
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_SCENE_PERSPECTIVE,
m_xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_PERSPECTIVE));
}
//light
{
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_SCENE_SHADE_MODE,
m_xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_SHADE_MODE));
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR,
m_xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR));
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_SCENE_TWO_SIDED_LIGHTING,
m_xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_TWO_SIDED_LIGHTING));
lcl_setLightSources( m_xDiagram, m_xOuterGroupShape );
}
//rotation
{
//set diagrams rotation is set exclusively via the transformation matrix
//don't set a camera at all!
//the camera's rotation is incorporated into this matrix
::basegfx::B3DHomMatrix aEffectiveTransformation;
aEffectiveTransformation.translate(-FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0, -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0, -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0);
if(!m_bRightAngledAxes)
aEffectiveTransformation.rotate(m_fXAnglePi,m_fYAnglePi,m_fZAnglePi);
else
aEffectiveTransformation.shearXY(m_fYAnglePi,-m_fXAnglePi);
//#i98497# 3D charts are rendered with wrong size
E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));
m_xOuterGroupShape->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX,
uno::Any( BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aEffectiveTransformation ) ) );
}
}
catch( const uno::Exception & )
{
DBG_UNHANDLED_EXCEPTION("chart2" );
}
//add floor plate
{
uno::Reference< beans::XPropertySet > xFloorProp;
if( m_xDiagram.is() )
xFloorProp.set( m_xDiagram->getFloor() );
Stripe aStripe( drawing::Position3D(0,0,0)
, drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME)
, drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0) );
aStripe.InvertNormal(true);
rtl::Reference<Svx3DPolygonObject> xShape =
ShapeFactory::createStripe(xOuterGroup_Shapes, aStripe
, xFloorProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided );
CuboidPlanePosition eBottomPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBottom( m_xDiagram ) );
if( !bAddFloorAndWall || (eBottomPos!=CuboidPlanePosition_Bottom) )
{
//we always need this object as dummy object for correct scene dimensions
//but it should not be visible in this case:
ShapeFactory::makeShapeInvisible( xShape );
}
else
{
OUString aFloorCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_FLOOR, u"" ) );//@todo read CID from model
ShapeFactory::setShapeName( xShape, aFloorCID );
}
}
//create an additional scene for the smaller inner coordinate region:
{
rtl::Reference<Svx3DSceneObject> xShapes2 = ShapeFactory::createGroup3D( xOuterGroup_Shapes,"testonly;CooContainer=XXX_CID" );
m_xCoordinateRegionShape = xShapes2;
try
{
double fXScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
double fYScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
double fZScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
::basegfx::B3DHomMatrix aM;
aM.translate(GRID_TO_WALL_DISTANCE/fXScale, GRID_TO_WALL_DISTANCE/fYScale, GRID_TO_WALL_DISTANCE/fZScale);
aM.scale( fXScale, fYScale, fZScale );
E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));
xShapes2->SvxShape::setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
, uno::Any(BaseGFXHelper::B3DHomMatrixToHomogenMatrix(aM)) );
}
catch( const uno::Exception& )
{
TOOLS_WARN_EXCEPTION("chart2", "" );
}
}
m_aCurrentPosWithoutAxes = m_aAvailablePosIncludingAxes;
m_aCurrentSizeWithoutAxes = m_aAvailableSizeIncludingAxes;
adjustPosAndSize_3d( m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes );
}
basegfx::B2IRectangle VDiagram::getCurrentRectangle() const
{
return BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes);
}
void VDiagram::reduceToMinimumSize()
{
if( !m_xOuterGroupShape.is() )
return;
awt::Size aMaxSize( m_aAvailableSizeIncludingAxes );
awt::Point aMaxPos( m_aAvailablePosIncludingAxes );
sal_Int32 nNewWidth = std::round(aMaxSize.Width/2.2);
sal_Int32 nNewHeight = std::round(aMaxSize.Height/2.2);
awt::Size aNewSize( nNewWidth, nNewHeight );
awt::Point aNewPos( aMaxPos );
aNewPos.X += nNewWidth;
aNewPos.Y += nNewHeight;
adjustPosAndSize( aNewPos, aNewSize );
}
::basegfx::B2IRectangle VDiagram::adjustInnerSize( const ::basegfx::B2IRectangle& rConsumedOuterRect )
{
awt::Point aNewPos = m_aCurrentPosWithoutAxes;
awt::Size aNewSize = m_aCurrentSizeWithoutAxes;
basegfx::B2IRectangle aAvailableOuterRect =
BaseGFXHelper::makeRectangle(m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes);
sal_Int32 nDeltaWidth = aAvailableOuterRect.getWidth() - rConsumedOuterRect.getWidth();
sal_Int32 nDeltaHeight = aAvailableOuterRect.getHeight() - rConsumedOuterRect.getHeight();
if( (aNewSize.Width + nDeltaWidth) < aAvailableOuterRect.getWidth()/3 )
nDeltaWidth = aAvailableOuterRect.getWidth()/3 - aNewSize.Width;
aNewSize.Width += nDeltaWidth;
if( (aNewSize.Height + nDeltaHeight) < aAvailableOuterRect.getHeight()/3 )
nDeltaHeight = aAvailableOuterRect.getHeight()/3 - aNewSize.Height;
aNewSize.Height += nDeltaHeight;
sal_Int32 nDiffLeft = rConsumedOuterRect.getMinX() - aAvailableOuterRect.getMinX();
sal_Int32 nDiffRight = aAvailableOuterRect.getMaxX() - rConsumedOuterRect.getMaxX();
if( nDiffLeft >= 0 )
aNewPos.X -= nDiffLeft;
else if( nDiffRight >= 0 )
{
if( nDiffRight > -nDiffLeft )
aNewPos.X += abs(nDiffLeft);
else if( nDiffRight > abs(nDeltaWidth) )
aNewPos.X += nDiffRight;
else
aNewPos.X += abs(nDeltaWidth);
}
sal_Int32 nDiffUp = rConsumedOuterRect.getMinY() - aAvailableOuterRect.getMinY();
sal_Int32 nDiffDown = aAvailableOuterRect.getMaxY() - rConsumedOuterRect.getMaxY();
if( nDiffUp >= 0 )
aNewPos.Y -= nDiffUp;
else if( nDiffDown >= 0 )
{
if( nDiffDown > -nDiffUp )
aNewPos.Y += abs(nDiffUp);
else if( nDiffDown > abs(nDeltaHeight) )
aNewPos.Y += nDiffDown;
else
aNewPos.Y += abs(nDeltaHeight);
}
return adjustPosAndSize( aNewPos, aNewSize );
}
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|