1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lathe3d.cxx,v $
10 * $Revision: 1.27.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include "svdglob.hxx"
36 #include <tools/poly.hxx>
37 #include <svx/svdpage.hxx>
38 #include "globl3d.hxx"
39 #include <svx/lathe3d.hxx>
40 #include <svx/xpoly.hxx>
41 #include <svx/svxids.hrc>
42 #include <svx/svdopath.hxx>
43 #include <svx/svdmodel.hxx>
44 #include <svx/svx3ditems.hxx>
45 #include <svx/sdr/properties/e3dlatheproperties.hxx>
46 #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
47 #include <basegfx/polygon/b2dpolypolygontools.hxx>
48 #include <basegfx/polygon/b2dpolygontools.hxx>
49 #include <basegfx/matrix/b2dhommatrix.hxx>
51 //////////////////////////////////////////////////////////////////////////////
52 // #110094# DrawContact section
54 sdr::contact::ViewContact
* E3dLatheObj::CreateObjectSpecificViewContact()
56 return new sdr::contact::ViewContactOfE3dLathe(*this);
59 //////////////////////////////////////////////////////////////////////////////
61 sdr::properties::BaseProperties
* E3dLatheObj::CreateObjectSpecificProperties()
63 return new sdr::properties::E3dLatheProperties(*this);
66 //////////////////////////////////////////////////////////////////////////////
68 TYPEINIT1(E3dLatheObj
, E3dCompoundObject
);
70 /*************************************************************************
72 |* Konstruktor aus 3D-Polygon, Scale gibt den Umrechnungsfaktor fuer
75 \************************************************************************/
77 E3dLatheObj::E3dLatheObj(E3dDefaultAttributes
& rDefault
, const basegfx::B2DPolyPolygon rPoly2D
)
78 : E3dCompoundObject(rDefault
),
81 // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
82 basegfx::B2DHomMatrix aMirrorY
;
83 aMirrorY
.scale(1.0, -1.0);
84 maPolyPoly2D
.transform(aMirrorY
);
87 SetDefaultAttributes(rDefault
);
89 // Ueberfluessige Punkte entfernen, insbesondere doppelte
90 // Start- und Endpunkte verhindern
91 maPolyPoly2D
.removeDoublePoints();
93 if(maPolyPoly2D
.count())
95 const basegfx::B2DPolygon
rPoly(maPolyPoly2D
.getB2DPolygon(0L));
96 sal_uInt32
nSegCnt(rPoly
.count());
98 if(nSegCnt
&& !rPoly
.isClosed())
103 GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt
));
107 /*************************************************************************
111 \************************************************************************/
113 E3dLatheObj::E3dLatheObj()
114 : E3dCompoundObject()
117 E3dDefaultAttributes aDefault
;
118 SetDefaultAttributes(aDefault
);
121 void E3dLatheObj::SetDefaultAttributes(E3dDefaultAttributes
& rDefault
)
123 GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault
.GetDefaultLatheSmoothed()));
124 GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault
.GetDefaultLatheSmoothFrontBack()));
125 GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault
.GetDefaultLatheCharacterMode()));
126 GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault
.GetDefaultLatheCloseFront()));
127 GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault
.GetDefaultLatheCloseBack()));
130 /*************************************************************************
132 |* Identifier zurueckgeben
134 \************************************************************************/
136 UINT16
E3dLatheObj::GetObjIdentifier() const
138 return E3D_LATHEOBJ_ID
;
141 /*************************************************************************
143 |* Zuweisungsoperator
145 \************************************************************************/
147 void E3dLatheObj::operator=(const SdrObject
& rObj
)
149 // erstmal alle Childs kopieren
150 E3dCompoundObject::operator=(rObj
);
152 // weitere Parameter kopieren
153 const E3dLatheObj
& r3DObj
= (const E3dLatheObj
&)rObj
;
155 maPolyPoly2D
= r3DObj
.maPolyPoly2D
;
158 /*************************************************************************
160 |* Wandle das Objekt in ein Gruppenobjekt bestehend aus n Polygonen
162 \************************************************************************/
164 SdrObject
*E3dLatheObj::DoConvertToPolyObj(BOOL
/*bBezier*/) const
169 /*************************************************************************
171 |* Neue Segmentierung (Beschreibung siehe Header-File)
173 \************************************************************************/
175 void E3dLatheObj::ReSegment(sal_uInt32 nHSegs
, sal_uInt32 nVSegs
)
177 if ((nHSegs
!= GetHorizontalSegments() || nVSegs
!= GetVerticalSegments()) &&
178 (nHSegs
!= 0 || nVSegs
!= 0))
180 GetProperties().SetObjectItemDirect(Svx3DHorizontalSegmentsItem(nHSegs
));
181 GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nVSegs
));
187 /*************************************************************************
189 |* Lokale Parameter setzen mit Geometrieneuerzeugung
191 \************************************************************************/
193 void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon
& rNew
)
195 if(maPolyPoly2D
!= rNew
)
198 maPolyPoly2D
.removeDoublePoints();
200 if(maPolyPoly2D
.count())
202 const basegfx::B2DPolygon
rPoly(maPolyPoly2D
.getB2DPolygon(0L));
203 sal_uInt32
nSegCnt(rPoly
.count());
205 if(nSegCnt
&& !rPoly
.isClosed())
210 GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt
));
217 /*************************************************************************
219 |* Get the name of the object (singular)
221 \************************************************************************/
223 void E3dLatheObj::TakeObjNameSingul(XubString
& rName
) const
225 rName
=ImpGetResStr(STR_ObjNameSingulLathe3d
);
227 String
aName( GetName() );
230 rName
+= sal_Unicode(' ');
231 rName
+= sal_Unicode('\'');
233 rName
+= sal_Unicode('\'');
237 /*************************************************************************
239 |* Get the name of the object (plural)
241 \************************************************************************/
243 void E3dLatheObj::TakeObjNamePlural(XubString
& rName
) const
245 rName
=ImpGetResStr(STR_ObjNamePluralLathe3d
);
248 /*************************************************************************
252 \************************************************************************/
254 BOOL
E3dLatheObj::IsBreakObjPossible()
259 SdrAttrObj
* E3dLatheObj::GetBreakObj()
262 basegfx::B3DPolyPolygon
aLathePoly3D(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D
));
263 basegfx::B2DPolyPolygon
aTransPoly(TransformToScreenCoor(aLathePoly3D
));
264 SdrPathObj
* pPathObj
= new SdrPathObj(OBJ_PLIN
, aTransPoly
);
269 SfxItemSet
aSet(GetObjectItemSet());
271 // Linien aktivieren, um Objekt garantiert sichtbar zu machen
272 aSet
.Put(XLineStyleItem(XLINE_SOLID
));
274 pPathObj
->SetMergedItemSet(aSet
);