update emoji autocorrect entries from po-files
[LibreOffice.git] / drawinglayer / source / processor3d / cutfindprocessor3d.cxx
blob3b30d3cb49cda15c3a63143ebb748341159a83dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/processor3d/cutfindprocessor3d.hxx>
21 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
22 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
23 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
24 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
25 #include <basegfx/polygon/b3dpolygon.hxx>
26 #include <basegfx/polygon/b3dpolygontools.hxx>
27 #include <basegfx/polygon/b3dpolypolygontools.hxx>
28 #include <drawinglayer/primitive3d/hiddengeometryprimitive3d.hxx>
32 namespace drawinglayer
34 namespace processor3d
36 CutFindProcessor::CutFindProcessor(const geometry::ViewInformation3D& rViewInformation,
37 const basegfx::B3DPoint& rFront,
38 const basegfx::B3DPoint& rBack,
39 bool bAnyHit)
40 : BaseProcessor3D(rViewInformation),
41 maFront(rFront),
42 maBack(rBack),
43 maResult(),
44 maCombinedTransform(),
45 mbAnyHit(bAnyHit),
46 mbUseInvisiblePrimitiveContent(true)
50 void CutFindProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
52 if(getAnyHit() && maResult.size())
54 // stop processing as soon as a hit was recognized
55 return;
58 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
59 switch(rCandidate.getPrimitive3DID())
61 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
63 // transform group.
64 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
66 // remember old and transform front, back to object coordinates
67 const basegfx::B3DPoint aLastFront(maFront);
68 const basegfx::B3DPoint aLastBack(maBack);
69 basegfx::B3DHomMatrix aInverseTrans(rPrimitive.getTransformation());
70 aInverseTrans.invert();
71 maFront *= aInverseTrans;
72 maBack *= aInverseTrans;
74 // remember current and create new transformation; add new object transform from right side
75 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
76 const geometry::ViewInformation3D aNewViewInformation3D(
77 aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
78 aLastViewInformation3D.getOrientation(),
79 aLastViewInformation3D.getProjection(),
80 aLastViewInformation3D.getDeviceToView(),
81 aLastViewInformation3D.getViewTime(),
82 aLastViewInformation3D.getExtendedInformationSequence());
83 updateViewInformation(aNewViewInformation3D);
85 // #i102956# remember needed back-transform for found cuts (combine from right side)
86 const basegfx::B3DHomMatrix aLastCombinedTransform(maCombinedTransform);
87 maCombinedTransform = maCombinedTransform * rPrimitive.getTransformation();
89 // let break down
90 process(rPrimitive.getChildren());
92 // restore transformations and front, back
93 maCombinedTransform = aLastCombinedTransform;
94 updateViewInformation(aLastViewInformation3D);
95 maFront = aLastFront;
96 maBack = aLastBack;
97 break;
99 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
101 // PolygonHairlinePrimitive3D, not used for hit test with planes, ignore. This
102 // means that also thick line expansion will not be hit-tested as
103 // PolyPolygonMaterialPrimitive3D
104 break;
106 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
108 // #i97321#
109 // For HatchTexturePrimitive3D, do not use the decomposition since it will produce
110 // clipped hatch lines in 3D. It can be used when the hatch also has a filling, but for
111 // simplicity, just use the children which are the PolyPolygonMaterialPrimitive3D
112 // which define the hatched areas anyways; for HitTest this is more than adequate
113 const primitive3d::HatchTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::HatchTexturePrimitive3D& >(rCandidate);
114 process(rPrimitive.getChildren());
115 break;
117 case PRIMITIVE3D_ID_HIDDENGEOMETRYPRIMITIVE3D :
119 // HiddenGeometryPrimitive3D; the default decomposition would return an empty seqence,
120 // so force this primitive to process its children directly if the switch is set
121 // (which is the default). Else, ignore invisible content
122 const primitive3d::HiddenGeometryPrimitive3D& rHiddenGeometry(static_cast< const primitive3d::HiddenGeometryPrimitive3D& >(rCandidate));
123 const primitive3d::Primitive3DSequence& rChildren = rHiddenGeometry.getChildren();
125 if(rChildren.hasElements())
127 if(getUseInvisiblePrimitiveContent())
129 process(rChildren);
133 break;
135 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D :
137 const primitive3d::UnifiedTransparenceTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::UnifiedTransparenceTexturePrimitive3D& >(rCandidate);
138 const primitive3d::Primitive3DSequence rChildren = rPrimitive.getChildren();
140 if(rChildren.getLength())
142 if(1.0 <= rPrimitive.getTransparence())
144 // not visible, but use for HitTest
145 if(getUseInvisiblePrimitiveContent())
147 process(rChildren);
150 else if(rPrimitive.getTransparence() >= 0.0 && rPrimitive.getTransparence() < 1.0)
152 // visible; use content
153 process(rChildren);
157 break;
159 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
161 // PolyPolygonMaterialPrimitive3D
162 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
164 if(!maFront.equal(maBack))
166 const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
167 const sal_uInt32 nPolyCount(rPolyPolygon.count());
169 if(nPolyCount)
171 const basegfx::B3DPolygon aPolygon(rPolyPolygon.getB3DPolygon(0));
172 const sal_uInt32 nPointCount(aPolygon.count());
174 if(nPointCount > 2)
176 const basegfx::B3DVector aPlaneNormal(aPolygon.getNormal());
178 if(!aPlaneNormal.equalZero())
180 const basegfx::B3DPoint aPointOnPlane(aPolygon.getB3DPoint(0));
181 double fCut(0.0);
183 if(basegfx::tools::getCutBetweenLineAndPlane(aPlaneNormal, aPointOnPlane, maFront, maBack, fCut))
185 const basegfx::B3DPoint aCutPoint(basegfx::interpolate(maFront, maBack, fCut));
187 if(basegfx::tools::isInside(rPolyPolygon, aCutPoint, false))
189 // #i102956# add result. Do not forget to do this in the coordinate
190 // system the processor get started with, so use the collected
191 // combined transformation from processed TransformPrimitive3D's
192 maResult.push_back(maCombinedTransform * aCutPoint);
200 break;
202 default :
204 // process recursively
205 process(rCandidate.get3DDecomposition(getViewInformation3D()));
206 break;
210 } // end of namespace processor3d
211 } // end of namespace drawinglayer
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */