1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: helplineprimitive2d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:08 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/helplineprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
42 #include <basegfx/polygon/b2dpolygonclipper.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <drawinglayer/geometry/viewinformation2d.hxx>
45 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
47 //////////////////////////////////////////////////////////////////////////////
49 using namespace com::sun::star
;
51 //////////////////////////////////////////////////////////////////////////////
53 namespace drawinglayer
57 Primitive2DSequence
HelplinePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
59 std::vector
< BasePrimitive2D
* > aTempPrimitiveTarget
;
61 if(!rViewInformation
.getViewport().isEmpty() && !getDirection().equalZero())
63 // position to view coordinates, DashLen and DashLen in logic
64 const basegfx::B2DPoint
aViewPosition(rViewInformation
.getObjectToViewTransformation() * getPosition());
68 default : // HELPLINESTYLE2D_POINT
70 const double fViewFixValue(15.0);
71 basegfx::B2DVector
aNormalizedDirection(getDirection());
72 aNormalizedDirection
.normalize();
73 aNormalizedDirection
*= fViewFixValue
;
74 const basegfx::B2DPoint
aStartA(aViewPosition
- aNormalizedDirection
);
75 const basegfx::B2DPoint
aEndA(aViewPosition
+ aNormalizedDirection
);
76 basegfx::B2DPolygon aLineA
;
77 aLineA
.append(aStartA
);
79 aLineA
.transform(rViewInformation
.getInverseObjectToViewTransformation());
80 PolygonMarkerPrimitive2D
* pNewA
= new PolygonMarkerPrimitive2D(aLineA
, getRGBColA(), getRGBColB(), getDiscreteDashLength());
81 aTempPrimitiveTarget
.push_back(pNewA
);
83 const basegfx::B2DVector
aPerpendicularNormalizedDirection(basegfx::getPerpendicular(aNormalizedDirection
));
84 const basegfx::B2DPoint
aStartB(aViewPosition
- aPerpendicularNormalizedDirection
);
85 const basegfx::B2DPoint
aEndB(aViewPosition
+ aPerpendicularNormalizedDirection
);
86 basegfx::B2DPolygon aLineB
;
87 aLineB
.append(aStartB
);
89 aLineB
.transform(rViewInformation
.getInverseObjectToViewTransformation());
90 PolygonMarkerPrimitive2D
* pNewB
= new PolygonMarkerPrimitive2D(aLineB
, getRGBColA(), getRGBColB(), getDiscreteDashLength());
91 aTempPrimitiveTarget
.push_back(pNewB
);
95 case HELPLINESTYLE2D_LINE
:
97 basegfx::B2DPolygon aLine
;
99 if(basegfx::areParallel(getDirection(), basegfx::B2DVector(1.0, 0.0)))
101 // parallel to X-Axis, get cuts with Y-Axes
102 const double fCutA((rViewInformation
.getDiscreteViewport().getMinX() - aViewPosition
.getX()) / getDirection().getX());
103 const double fCutB((rViewInformation
.getDiscreteViewport().getMaxX() - aViewPosition
.getX()) / getDirection().getX());
104 const basegfx::B2DPoint
aPosA(aViewPosition
+ (fCutA
* getDirection()));
105 const basegfx::B2DPoint
aPosB(aViewPosition
+ (fCutB
* getDirection()));
106 const bool bBothLeft(aPosA
.getX() < rViewInformation
.getDiscreteViewport().getMinX() && aPosB
.getX() < rViewInformation
.getDiscreteViewport().getMinX());
107 const bool bBothRight(aPosA
.getX() > rViewInformation
.getDiscreteViewport().getMaxX() && aPosB
.getX() < rViewInformation
.getDiscreteViewport().getMaxX());
109 if(!bBothLeft
&& !bBothRight
)
117 // get cuts with X-Axes
118 const double fCutA((rViewInformation
.getDiscreteViewport().getMinY() - aViewPosition
.getY()) / getDirection().getY());
119 const double fCutB((rViewInformation
.getDiscreteViewport().getMaxY() - aViewPosition
.getY()) / getDirection().getY());
120 const basegfx::B2DPoint
aPosA(aViewPosition
+ (fCutA
* getDirection()));
121 const basegfx::B2DPoint
aPosB(aViewPosition
+ (fCutB
* getDirection()));
122 const bool bBothAbove(aPosA
.getY() < rViewInformation
.getDiscreteViewport().getMinY() && aPosB
.getY() < rViewInformation
.getDiscreteViewport().getMinY());
123 const bool bBothBelow(aPosA
.getY() > rViewInformation
.getDiscreteViewport().getMaxY() && aPosB
.getY() < rViewInformation
.getDiscreteViewport().getMaxY());
125 if(!bBothAbove
&& !bBothBelow
)
134 // clip against visible area
135 const basegfx::B2DPolyPolygon
aResult(basegfx::tools::clipPolygonOnRange(aLine
, rViewInformation
.getDiscreteViewport(), true, true));
137 for(sal_uInt32
a(0L); a
< aResult
.count(); a
++)
139 basegfx::B2DPolygon
aPart(aResult
.getB2DPolygon(a
));
140 aPart
.transform(rViewInformation
.getInverseObjectToViewTransformation());
141 PolygonMarkerPrimitive2D
* pNew
= new PolygonMarkerPrimitive2D(aPart
, getRGBColA(), getRGBColB(), getDiscreteDashLength());
142 aTempPrimitiveTarget
.push_back(pNew
);
151 // prepare return value
152 Primitive2DSequence
aRetval(aTempPrimitiveTarget
.size());
154 for(sal_uInt32
a(0L); a
< aTempPrimitiveTarget
.size(); a
++)
156 const Primitive2DReference
xRef(aTempPrimitiveTarget
[a
]);
163 HelplinePrimitive2D::HelplinePrimitive2D(
164 const basegfx::B2DPoint
& rPosition
,
165 const basegfx::B2DVector
& rDirection
,
166 HelplineStyle2D eStyle
,
167 const basegfx::BColor
& rRGBColA
,
168 const basegfx::BColor
& rRGBColB
,
169 double fDiscreteDashLength
)
171 maPosition(rPosition
),
172 maDirection(rDirection
),
176 mfDiscreteDashLength(fDiscreteDashLength
),
177 maLastObjectToViewTransformation(),
182 bool HelplinePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
184 if(BasePrimitive2D::operator==(rPrimitive
))
186 const HelplinePrimitive2D
& rCompare
= (HelplinePrimitive2D
&)rPrimitive
;
188 return (getPosition() == rCompare
.getPosition()
189 && getDirection() == rCompare
.getDirection()
190 && getStyle() == rCompare
.getStyle()
191 && getRGBColA() == rCompare
.getRGBColA()
192 && getRGBColB() == rCompare
.getRGBColB()
193 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
199 Primitive2DSequence
HelplinePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
201 ::osl::MutexGuard
aGuard( m_aMutex
);
203 if(getLocalDecomposition().hasElements())
205 if(maLastViewport
!= rViewInformation
.getViewport() || maLastObjectToViewTransformation
!= rViewInformation
.getObjectToViewTransformation())
207 // conditions of last local decomposition have changed, delete
208 const_cast< HelplinePrimitive2D
* >(this)->setLocalDecomposition(Primitive2DSequence());
212 if(!getLocalDecomposition().hasElements())
214 // remember ViewRange and ViewTransformation
215 const_cast< HelplinePrimitive2D
* >(this)->maLastObjectToViewTransformation
= rViewInformation
.getObjectToViewTransformation();
216 const_cast< HelplinePrimitive2D
* >(this)->maLastViewport
= rViewInformation
.getViewport();
219 // use parent implementation
220 return BasePrimitive2D::get2DDecomposition(rViewInformation
);
224 ImplPrimitrive2DIDBlock(HelplinePrimitive2D
, PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D
)
226 } // end of namespace primitive2d
227 } // end of namespace drawinglayer
229 //////////////////////////////////////////////////////////////////////////////