1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/sdr/contact/viewobjectcontactofe3dscene.hxx>
32 #include <svx/sdr/contact/displayinfo.hxx>
33 #include <svx/sdr/contact/objectcontact.hxx>
34 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
35 #include <basegfx/matrix/b3dhommatrix.hxx>
36 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
37 #include <basegfx/color/bcolormodifier.hxx>
38 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
39 #include <svx/sdr/contact/viewobjectcontactofe3d.hxx>
40 #include <basegfx/tools/canvastools.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 using namespace com::sun::star;
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 namespace
49 {
50 	// Helper method to recursively travel the DrawHierarchy for 3D objects contained in
51 	// the 2D Scene. This will chreate all VOCs for the currenbt OC which are needed
52 	// for ActionChanged() functionality
53 	void impInternalSubHierarchyTraveller(const sdr::contact::ViewObjectContact& rVOC)
54 	{
55 		const sdr::contact::ViewContact& rVC = rVOC.GetViewContact();
56 		const sal_uInt32 nSubHierarchyCount(rVC.GetObjectCount());
57 
58 		for(sal_uInt32 a(0); a < nSubHierarchyCount; a++)
59 		{
60 			const sdr::contact::ViewObjectContact& rCandidate(rVC.GetViewContact(a).GetViewObjectContact(rVOC.GetObjectContact()));
61 			impInternalSubHierarchyTraveller(rCandidate);
62 		}
63 	}
64 } // end of anonymous namespace
65 
66 //////////////////////////////////////////////////////////////////////////////
67 
68 namespace sdr
69 {
70 	namespace contact
71 	{
72 		ViewObjectContactOfE3dScene::ViewObjectContactOfE3dScene(ObjectContact& rObjectContact, ViewContact& rViewContact)
73 		:	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
74 		{
75 		}
76 
77 		ViewObjectContactOfE3dScene::~ViewObjectContactOfE3dScene()
78 		{
79 		}
80 
81 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfE3dScene::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
82 		{
83 			// handle ghosted, else the whole 3d group will be encapsulated to a ghosted primitive set (see below)
84 			const bool bHandleGhostedDisplay(GetObjectContact().DoVisualizeEnteredGroup() && !GetObjectContact().isOutputToPrinter() && rDisplayInfo.IsGhostedDrawModeActive());
85 			const bool bIsActiveVC(bHandleGhostedDisplay && GetObjectContact().getActiveViewContact() == &GetViewContact());
86 
87 			if(bIsActiveVC)
88 			{
89 				// switch off ghosted, display contents normal
90 				const_cast< DisplayInfo& >(rDisplayInfo).ClearGhostedDrawMode();
91 			}
92 
93 			// create 2d primitive with content, use layer visibility test
94 			// this uses no ghosted mode, so scenes in scenes and entering them will not
95 			// support ghosted for now. This is no problem currently but would need to be
96 			// added when sub-groups in 3d will be added one day.
97 			const ViewContactOfE3dScene& rViewContact = dynamic_cast< ViewContactOfE3dScene& >(GetViewContact());
98 			const SetOfByte& rVisibleLayers = rDisplayInfo.GetProcessLayers();
99 			drawinglayer::primitive2d::Primitive2DSequence xRetval(rViewContact.createScenePrimitive2DSequence(&rVisibleLayers));
100 
101 			if(xRetval.hasElements())
102 			{
103 				// handle GluePoint
104 				if(!GetObjectContact().isOutputToPrinter() && GetObjectContact().AreGluePointsVisible())
105 				{
106 					const drawinglayer::primitive2d::Primitive2DSequence xGlue(GetViewContact().createGluePointPrimitive2DSequence());
107 
108 					if(xGlue.hasElements())
109 					{
110                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xGlue);
111 					}
112 				}
113 
114 				// handle ghosted
115 				if(isPrimitiveGhosted(rDisplayInfo))
116 				{
117 					const ::basegfx::BColor aRGBWhite(1.0, 1.0, 1.0);
118 					const ::basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, ::basegfx::BCOLORMODIFYMODE_INTERPOLATE);
119                     const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ModifiedColorPrimitive2D(xRetval, aBColorModifier));
120 
121                     xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
122 				}
123 			}
124 
125 			if(bIsActiveVC)
126 			{
127 				// set back, display ghosted again
128 				const_cast< DisplayInfo& >(rDisplayInfo).SetGhostedDrawMode();
129 			}
130 
131 			return xRetval;
132 		}
133 
134 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfE3dScene::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
135 		{
136 			// To get the VOCs for the contained 3D objects created to get the correct
137 			// Draw hierarchy and ActionChanged() working properly, travel the DrawHierarchy
138 			// using a local tooling method
139 			impInternalSubHierarchyTraveller(*this);
140 
141 			// call parent
142 			return ViewObjectContactOfSdrObj::getPrimitive2DSequenceHierarchy(rDisplayInfo);
143 		}
144 	} // end of namespace contact
145 } // end of namespace sdr
146 
147 //////////////////////////////////////////////////////////////////////////////
148 // eof
149