xref: /AOO41X/main/svx/source/sdr/contact/viewobjectcontactofe3dscene.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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
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     {
68         ViewObjectContactOfE3dScene::ViewObjectContactOfE3dScene(ObjectContact& rObjectContact, ViewContact& rViewContact)
69         :   ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
70         {
71         }
72 
73         ViewObjectContactOfE3dScene::~ViewObjectContactOfE3dScene()
74         {
75         }
76 
77         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                 // handle GluePoint
100                 if(!GetObjectContact().isOutputToPrinter() && GetObjectContact().AreGluePointsVisible())
101                 {
102                     const drawinglayer::primitive2d::Primitive2DSequence xGlue(GetViewContact().createGluePointPrimitive2DSequence());
103 
104                     if(xGlue.hasElements())
105                     {
106                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xGlue);
107                     }
108                 }
109 
110                 // handle ghosted
111                 if(isPrimitiveGhosted(rDisplayInfo))
112                 {
113                     const ::basegfx::BColor aRGBWhite(1.0, 1.0, 1.0);
114                     const ::basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, ::basegfx::BCOLORMODIFYMODE_INTERPOLATE);
115                     const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ModifiedColorPrimitive2D(xRetval, aBColorModifier));
116 
117                     xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
118                 }
119             }
120 
121             if(bIsActiveVC)
122             {
123                 // set back, display ghosted again
124                 const_cast< DisplayInfo& >(rDisplayInfo).SetGhostedDrawMode();
125             }
126 
127             return xRetval;
128         }
129 
130         drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfE3dScene::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
131         {
132             // To get the VOCs for the contained 3D objects created to get the correct
133             // Draw hierarchy and ActionChanged() working properly, travel the DrawHierarchy
134             // using a local tooling method
135             impInternalSubHierarchyTraveller(*this);
136 
137             // call parent
138             return ViewObjectContactOfSdrObj::getPrimitive2DSequenceHierarchy(rDisplayInfo);
139         }
140     } // end of namespace contact
141 } // end of namespace sdr
142 
143 //////////////////////////////////////////////////////////////////////////////
144 // eof
145