1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewobjectcontactofe3dscene.hxx>
28 #include <svx/sdr/contact/displayinfo.hxx>
29 #include <svx/sdr/contact/objectcontact.hxx>
30 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
31 #include <basegfx/matrix/b3dhommatrix.hxx>
32 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
33 #include <basegfx/color/bcolormodifier.hxx>
34 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
35 #include <svx/sdr/contact/viewobjectcontactofe3d.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 using namespace com::sun::star;
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace
45 {
46 	// Helper method to recursively travel the DrawHierarchy for 3D objects contained in
47 	// the 2D Scene. This will chreate all VOCs for the currenbt OC which are needed
48 	// for ActionChanged() functionality
impInternalSubHierarchyTraveller(const sdr::contact::ViewObjectContact & rVOC)49 	void impInternalSubHierarchyTraveller(const sdr::contact::ViewObjectContact& rVOC)
50 	{
51 		const sdr::contact::ViewContact& rVC = rVOC.GetViewContact();
52 		const sal_uInt32 nSubHierarchyCount(rVC.GetObjectCount());
53 
54 		for(sal_uInt32 a(0); a < nSubHierarchyCount; a++)
55 		{
56 			const sdr::contact::ViewObjectContact& rCandidate(rVC.GetViewContact(a).GetViewObjectContact(rVOC.GetObjectContact()));
57 			impInternalSubHierarchyTraveller(rCandidate);
58 		}
59 	}
60 } // end of anonymous namespace
61 
62 //////////////////////////////////////////////////////////////////////////////
63 
64 namespace sdr
65 {
66 	namespace contact
67 	{
ViewObjectContactOfE3dScene(ObjectContact & rObjectContact,ViewContact & rViewContact)68 		ViewObjectContactOfE3dScene::ViewObjectContactOfE3dScene(ObjectContact& rObjectContact, ViewContact& rViewContact)
69 		:	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
70 		{
71 		}
72 
~ViewObjectContactOfE3dScene()73 		ViewObjectContactOfE3dScene::~ViewObjectContactOfE3dScene()
74 		{
75 		}
76 
createPrimitive2DSequence(const DisplayInfo & rDisplayInfo) const77 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfE3dScene::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
78 		{
79 			// handle ghosted, else the whole 3d group will be encapsulated to a ghosted primitive set (see below)
80 			const bool bHandleGhostedDisplay(GetObjectContact().DoVisualizeEnteredGroup() && !GetObjectContact().isOutputToPrinter() && rDisplayInfo.IsGhostedDrawModeActive());
81 			const bool bIsActiveVC(bHandleGhostedDisplay && GetObjectContact().getActiveViewContact() == &GetViewContact());
82 
83 			if(bIsActiveVC)
84 			{
85 				// switch off ghosted, display contents normal
86 				const_cast< DisplayInfo& >(rDisplayInfo).ClearGhostedDrawMode();
87 			}
88 
89 			// create 2d primitive with content, use layer visibility test
90 			// this uses no ghosted mode, so scenes in scenes and entering them will not
91 			// support ghosted for now. This is no problem currently but would need to be
92 			// added when sub-groups in 3d will be added one day.
93 			const ViewContactOfE3dScene& rViewContact = dynamic_cast< ViewContactOfE3dScene& >(GetViewContact());
94 			const SetOfByte& rVisibleLayers = rDisplayInfo.GetProcessLayers();
95 			drawinglayer::primitive2d::Primitive2DSequence xRetval(rViewContact.createScenePrimitive2DSequence(&rVisibleLayers));
96 
97 			if(xRetval.hasElements())
98 			{
99                 // allow evtl. embedding in object-specific infos, e.g. Name, Title, Description
100                 xRetval = rViewContact.embedToObjectSpecificInformation(xRetval);
101 
102                 // handle GluePoint
103 				if(!GetObjectContact().isOutputToPrinter() && GetObjectContact().AreGluePointsVisible())
104 				{
105 					const drawinglayer::primitive2d::Primitive2DSequence xGlue(GetViewContact().createGluePointPrimitive2DSequence());
106 
107 					if(xGlue.hasElements())
108 					{
109                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xGlue);
110 					}
111 				}
112 
113                 // handle ghosted
114                 if(isPrimitiveGhosted(rDisplayInfo))
115                 {
116                     const ::basegfx::BColor aRGBWhite(1.0, 1.0, 1.0);
117                     const ::basegfx::BColorModifierSharedPtr aBColorModifier(
118                         new basegfx::BColorModifier_interpolate(
119                             aRGBWhite,
120                             0.5));
121                     const drawinglayer::primitive2d::Primitive2DReference xReference(
122                         new drawinglayer::primitive2d::ModifiedColorPrimitive2D(
123                             xRetval,
124                             aBColorModifier));
125 
126                     xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
127                 }
128             }
129 
130 			if(bIsActiveVC)
131 			{
132 				// set back, display ghosted again
133 				const_cast< DisplayInfo& >(rDisplayInfo).SetGhostedDrawMode();
134 			}
135 
136 			return xRetval;
137 		}
138 
getPrimitive2DSequenceHierarchy(DisplayInfo & rDisplayInfo) const139 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfE3dScene::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
140 		{
141 			// To get the VOCs for the contained 3D objects created to get the correct
142 			// Draw hierarchy and ActionChanged() working properly, travel the DrawHierarchy
143 			// using a local tooling method
144 			impInternalSubHierarchyTraveller(*this);
145 
146 			// call parent
147 			return ViewObjectContactOfSdrObj::getPrimitive2DSequenceHierarchy(rDisplayInfo);
148 		}
149 	} // end of namespace contact
150 } // end of namespace sdr
151 
152 //////////////////////////////////////////////////////////////////////////////
153 // eof
154