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 #ifndef INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX
25 #define INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX
26 
27 #include <cppuhelper/basemutex.hxx>
28 #include <cppuhelper/compbase3.hxx>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/rendering/FillRule.hpp>
31 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
32 #include <com/sun/star/rendering/XBezierPolyPolygon2D.hpp>
33 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 #include <basegfx/basegfxdllapi.h>
35 
36 
37 namespace basegfx
38 {
39 namespace unotools
40 {
41     typedef ::cppu::WeakComponentImplHelper3<
42        	  ::com::sun::star::rendering::XLinePolyPolygon2D,
43           ::com::sun::star::rendering::XBezierPolyPolygon2D,
44           ::com::sun::star::lang::XServiceInfo > UnoPolyPolygonBase;
45 
46     class BASEGFX_DLLPUBLIC UnoPolyPolygon : private cppu::BaseMutex,
47                            public UnoPolyPolygonBase
48     {
49     public:
50         explicit UnoPolyPolygon( const B2DPolyPolygon& );
51 
52         // XPolyPolygon2D
53         virtual void SAL_CALL addPolyPolygon( const ::com::sun::star::geometry::RealPoint2D& position, const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& polyPolygon ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
54         virtual ::sal_Int32 SAL_CALL getNumberOfPolygons(  ) throw (::com::sun::star::uno::RuntimeException);
55         virtual ::sal_Int32 SAL_CALL getNumberOfPolygonPoints( ::sal_Int32 polygon ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
56         virtual ::com::sun::star::rendering::FillRule SAL_CALL getFillRule(  ) throw (::com::sun::star::uno::RuntimeException);
57         virtual void SAL_CALL setFillRule( ::com::sun::star::rendering::FillRule fillRule ) throw (::com::sun::star::uno::RuntimeException);
58         virtual ::sal_Bool SAL_CALL isClosed( ::sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
59         virtual void SAL_CALL setClosed( ::sal_Int32 index, ::sal_Bool closedState ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
60 
61         // XLinePolyPolygon2D
62         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > > SAL_CALL getPoints( ::sal_Int32 nPolygonIndex, ::sal_Int32 nNumberOfPolygons, ::sal_Int32 nPointIndex, ::sal_Int32 nNumberOfPoints ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
63         virtual void SAL_CALL setPoints( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& points, ::sal_Int32 nPolygonIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
64         virtual ::com::sun::star::geometry::RealPoint2D SAL_CALL getPoint( ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
65         virtual void SAL_CALL setPoint( const ::com::sun::star::geometry::RealPoint2D& point, ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
66 
67         // XBezierPolyPolygon2D
68         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > > SAL_CALL getBezierSegments( ::sal_Int32 nPolygonIndex, ::sal_Int32 nNumberOfPolygons, ::sal_Int32 nPointIndex, ::sal_Int32 nNumberOfPoints ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
69         virtual void SAL_CALL setBezierSegments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& points, ::sal_Int32 nPolygonIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
70         virtual ::com::sun::star::geometry::RealBezierSegment2D SAL_CALL getBezierSegment( ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
71         virtual void SAL_CALL setBezierSegment( const ::com::sun::star::geometry::RealBezierSegment2D& point, ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
72 
73         // XServiceInfo
74         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
75         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
76         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
77 
78         B2DPolyPolygon getPolyPolygon() const;
79 
80     protected:
81         /// Check whether index is a valid polygon index
checkIndex(sal_Int32 nIndex) const82         void checkIndex( sal_Int32 nIndex ) const // throw (::com::sun::star::lang::IndexOutOfBoundsException);
83         {
84             if( nIndex < 0 || nIndex >= static_cast<sal_Int32>(maPolyPoly.count()) )
85                 throw ::com::sun::star::lang::IndexOutOfBoundsException();
86         }
87 
88         B2DPolyPolygon getSubsetPolyPolygon( sal_Int32 nPolygonIndex,
89                                              sal_Int32 nNumberOfPolygons,
90                                              sal_Int32 nPointIndex,
91                                              sal_Int32 nNumberOfPoints ) const;
92 
93         /// Get cow copy of internal polygon. not thread-safe outside this object.
94         B2DPolyPolygon getPolyPolygonUnsafe() const;
95 
96         /// Called whenever internal polypolygon gets modified
modifying() const97         virtual void modifying() const {}
98 
99     private:
100         UnoPolyPolygon( const UnoPolyPolygon& );
101         UnoPolyPolygon& operator=( const UnoPolyPolygon& );
102 
103         B2DPolyPolygon                        maPolyPoly;
104         ::com::sun::star::rendering::FillRule meFillRule;
105     };
106 }
107 }
108 
109 #endif /* INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX */
110