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_drawinglayer.hxx" 26 27 #include <drawinglayer/processor3d/geometry2dextractor.hxx> 28 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx> 29 #include <drawinglayer/primitive3d/transformprimitive3d.hxx> 30 #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx> 31 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx> 32 #include <basegfx/polygon/b2dpolygontools.hxx> 33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 34 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx> 35 #include <basegfx/polygon/b2dpolypolygontools.hxx> 36 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 37 #include <drawinglayer/primitive3d/textureprimitive3d.hxx> 38 39 ////////////////////////////////////////////////////////////////////////////// 40 41 using namespace com::sun::star; 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 namespace drawinglayer 46 { 47 namespace processor3d 48 { 49 // as tooling, the process() implementation takes over API handling and calls this 50 // virtual render method when the primitive implementation is BasePrimitive3D-based. processBasePrimitive3D(const primitive3d::BasePrimitive3D & rCandidate)51 void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate) 52 { 53 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch 54 switch(rCandidate.getPrimitive3DID()) 55 { 56 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D : 57 { 58 // transform group. Remember current transformations 59 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate); 60 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D()); 61 62 // create new transformation; add new object transform from right side 63 const geometry::ViewInformation3D aNewViewInformation3D( 64 aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(), 65 aLastViewInformation3D.getOrientation(), 66 aLastViewInformation3D.getProjection(), 67 aLastViewInformation3D.getDeviceToView(), 68 aLastViewInformation3D.getViewTime(), 69 aLastViewInformation3D.getExtendedInformationSequence()); 70 updateViewInformation(aNewViewInformation3D); 71 72 // let break down recursively 73 process(rPrimitive.getChildren()); 74 75 // restore transformations 76 updateViewInformation(aLastViewInformation3D); 77 break; 78 } 79 case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D : 80 { 81 // ModifiedColorPrimitive3D; push, process and pop 82 const primitive3d::ModifiedColorPrimitive3D& rModifiedCandidate = static_cast< const primitive3d::ModifiedColorPrimitive3D& >(rCandidate); 83 const primitive3d::Primitive3DSequence& rSubSequence = rModifiedCandidate.getChildren(); 84 85 if(rSubSequence.hasElements()) 86 { 87 maBColorModifierStack.push(rModifiedCandidate.getColorModifier()); 88 process(rModifiedCandidate.getChildren()); 89 maBColorModifierStack.pop(); 90 } 91 break; 92 } 93 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D : 94 { 95 // PolygonHairlinePrimitive3D 96 const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate); 97 basegfx::B2DPolygon a2DHairline(basegfx::tools::createB2DPolygonFromB3DPolygon(rPrimitive.getB3DPolygon(), getViewInformation3D().getObjectToView())); 98 99 if(a2DHairline.count()) 100 { 101 a2DHairline.transform(getObjectTransformation()); 102 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getBColor())); 103 const primitive2d::Primitive2DReference xRef(new primitive2d::PolygonHairlinePrimitive2D(a2DHairline, aModifiedColor)); 104 primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef); 105 } 106 break; 107 } 108 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D : 109 { 110 // PolyPolygonMaterialPrimitive3D 111 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate); 112 basegfx::B2DPolyPolygon a2DFill(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive.getB3DPolyPolygon(), getViewInformation3D().getObjectToView())); 113 114 if(a2DFill.count()) 115 { 116 a2DFill.transform(getObjectTransformation()); 117 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getMaterial().getColor())); 118 const primitive2d::Primitive2DReference xRef(new primitive2d::PolyPolygonColorPrimitive2D(a2DFill, aModifiedColor)); 119 primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef); 120 } 121 break; 122 } 123 case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D : 124 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D : 125 case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D : 126 case PRIMITIVE3D_ID_TRANSPARENCETEXTUREPRIMITIVE3D : 127 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D : 128 { 129 // TexturePrimitive3D: Process children, do not try to decompose 130 const primitive3d::TexturePrimitive3D& rTexturePrimitive = static_cast< const primitive3d::TexturePrimitive3D& >(rCandidate); 131 const primitive3d::Primitive3DSequence aChildren(rTexturePrimitive.getChildren()); 132 133 if(aChildren.hasElements()) 134 { 135 process(aChildren); 136 } 137 break; 138 } 139 case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D : 140 { 141 // accept but ignore labels and shadow; these should be extracted separately 142 break; 143 } 144 default : 145 { 146 // process recursively 147 process(rCandidate.get3DDecomposition(getViewInformation3D())); 148 break; 149 } 150 } 151 } 152 Geometry2DExtractingProcessor(const geometry::ViewInformation3D & rViewInformation,const basegfx::B2DHomMatrix & rObjectTransformation)153 Geometry2DExtractingProcessor::Geometry2DExtractingProcessor( 154 const geometry::ViewInformation3D& rViewInformation, 155 const basegfx::B2DHomMatrix& rObjectTransformation) 156 : BaseProcessor3D(rViewInformation), 157 maPrimitive2DSequence(), 158 maObjectTransformation(rObjectTransformation), 159 maBColorModifierStack() 160 { 161 } 162 } // end of namespace processor3d 163 } // end of namespace drawinglayer 164 165 ////////////////////////////////////////////////////////////////////////////// 166 // eof 167