/src/libreoffice/drawinglayer/source/primitive3d/baseprimitive3d.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <drawinglayer/primitive3d/baseprimitive3d.hxx> |
21 | | #include <drawinglayer/geometry/viewinformation3d.hxx> |
22 | | #include <basegfx/utils/canvastools.hxx> |
23 | | #include <comphelper/sequence.hxx> |
24 | | |
25 | | |
26 | | using namespace com::sun::star; |
27 | | |
28 | | |
29 | | namespace drawinglayer::primitive3d |
30 | | { |
31 | | BasePrimitive3D::BasePrimitive3D() |
32 | 0 | { |
33 | 0 | } |
34 | | |
35 | | BasePrimitive3D::~BasePrimitive3D() |
36 | 0 | { |
37 | 0 | } |
38 | | |
39 | | bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const |
40 | 0 | { |
41 | 0 | return (getPrimitive3DID() == rPrimitive.getPrimitive3DID()); |
42 | 0 | } |
43 | | |
44 | | basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const |
45 | 0 | { |
46 | 0 | return get3DDecomposition(rViewInformation).getB3DRange(rViewInformation); |
47 | 0 | } |
48 | | |
49 | | Primitive3DContainer BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const |
50 | 0 | { |
51 | 0 | return Primitive3DContainer(); |
52 | 0 | } |
53 | | |
54 | | css::uno::Sequence< ::css::uno::Reference< ::css::graphic::XPrimitive3D > > SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) |
55 | 0 | { |
56 | 0 | const geometry::ViewInformation3D aViewInformation(rViewParameters); |
57 | 0 | return comphelper::containerToSequence(get3DDecomposition(aViewInformation)); |
58 | 0 | } |
59 | | |
60 | | css::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) |
61 | 0 | { |
62 | 0 | const geometry::ViewInformation3D aViewInformation(rViewParameters); |
63 | 0 | return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation)); |
64 | 0 | } |
65 | | |
66 | | |
67 | | Primitive3DContainer BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const |
68 | 0 | { |
69 | 0 | return Primitive3DContainer(); |
70 | 0 | } |
71 | | |
72 | | BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D() |
73 | 0 | { |
74 | 0 | } |
75 | | |
76 | | Primitive3DContainer BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const |
77 | 0 | { |
78 | 0 | std::unique_lock aGuard( m_aMutex ); |
79 | |
|
80 | 0 | if(getBuffered3DDecomposition().empty()) |
81 | 0 | { |
82 | 0 | const Primitive3DContainer aNewSequence(create3DDecomposition(rViewInformation)); |
83 | 0 | const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence); |
84 | 0 | } |
85 | |
|
86 | 0 | return getBuffered3DDecomposition(); |
87 | 0 | } |
88 | | |
89 | | // tooling |
90 | | |
91 | | // get range3D from a given Primitive3DReference |
92 | | basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation) |
93 | 0 | { |
94 | 0 | basegfx::B3DRange aRetval; |
95 | |
|
96 | 0 | if(rCandidate.is()) |
97 | 0 | { |
98 | 0 | const BasePrimitive3D* pCandidate(static_cast< BasePrimitive3D* >(rCandidate.get())); |
99 | 0 | aRetval.expand(pCandidate->getB3DRange(aViewInformation)); |
100 | 0 | } |
101 | |
|
102 | 0 | return aRetval; |
103 | 0 | } |
104 | | |
105 | | // get range3D from a given Primitive3DContainer |
106 | | basegfx::B3DRange Primitive3DContainer::getB3DRange(const geometry::ViewInformation3D& aViewInformation) const |
107 | 0 | { |
108 | 0 | basegfx::B3DRange aRetval; |
109 | |
|
110 | 0 | if(!empty()) |
111 | 0 | { |
112 | 0 | const size_t nCount(size()); |
113 | |
|
114 | 0 | for(size_t a(0); a < nCount; a++) |
115 | 0 | { |
116 | 0 | aRetval.expand(getB3DRangeFromPrimitive3DReference((*this)[a], aViewInformation)); |
117 | 0 | } |
118 | 0 | } |
119 | |
|
120 | 0 | return aRetval; |
121 | 0 | } |
122 | | |
123 | | bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB) |
124 | 0 | { |
125 | 0 | const bool bAIs(rxA.is()); |
126 | |
|
127 | 0 | if(bAIs != rxB.is()) |
128 | 0 | { |
129 | 0 | return false; |
130 | 0 | } |
131 | | |
132 | 0 | if(!bAIs) |
133 | 0 | { |
134 | 0 | return true; |
135 | 0 | } |
136 | | |
137 | 0 | const BasePrimitive3D* pA(static_cast< const BasePrimitive3D* >(rxA.get())); |
138 | 0 | const BasePrimitive3D* pB(static_cast< const BasePrimitive3D* >(rxB.get())); |
139 | |
|
140 | 0 | return pA->operator==(*pB); |
141 | 0 | } |
142 | | |
143 | | bool Primitive3DContainer::operator==(const Primitive3DContainer& rB) const |
144 | 0 | { |
145 | 0 | const bool bAHasElements(!empty()); |
146 | |
|
147 | 0 | if(bAHasElements != !rB.empty()) |
148 | 0 | { |
149 | 0 | return false; |
150 | 0 | } |
151 | | |
152 | 0 | if(!bAHasElements) |
153 | 0 | { |
154 | 0 | return true; |
155 | 0 | } |
156 | | |
157 | 0 | const size_t nCount(size()); |
158 | |
|
159 | 0 | if(nCount != rB.size()) |
160 | 0 | { |
161 | 0 | return false; |
162 | 0 | } |
163 | | |
164 | 0 | for(size_t a(0); a < nCount; a++) |
165 | 0 | { |
166 | 0 | if(!arePrimitive3DReferencesEqual((*this)[a], rB[a])) |
167 | 0 | { |
168 | 0 | return false; |
169 | 0 | } |
170 | 0 | } |
171 | | |
172 | 0 | return true; |
173 | 0 | } |
174 | | |
175 | | void Primitive3DContainer::append(const Primitive3DContainer& rSource) |
176 | 0 | { |
177 | 0 | insert(end(), rSource.begin(), rSource.end()); |
178 | 0 | } |
179 | | |
180 | | } // end of namespace |
181 | | |
182 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |