xref: /trunk/main/svx/source/engine3d/lathe3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "svx/svdstr.hrc"
32*cdf0e10cSrcweir #include "svx/svdglob.hxx"
33*cdf0e10cSrcweir #include <tools/poly.hxx>
34*cdf0e10cSrcweir #include <svx/svdpage.hxx>
35*cdf0e10cSrcweir #include "svx/globl3d.hxx"
36*cdf0e10cSrcweir #include <svx/lathe3d.hxx>
37*cdf0e10cSrcweir #include <svx/xpoly.hxx>
38*cdf0e10cSrcweir #include <svx/svxids.hrc>
39*cdf0e10cSrcweir #include <svx/svdopath.hxx>
40*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
41*cdf0e10cSrcweir #include <svx/svx3ditems.hxx>
42*cdf0e10cSrcweir #include <svx/sdr/properties/e3dlatheproperties.hxx>
43*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
44*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
45*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
46*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
49*cdf0e10cSrcweir // #110094# DrawContact section
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir sdr::contact::ViewContact* E3dLatheObj::CreateObjectSpecificViewContact()
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir     return new sdr::contact::ViewContactOfE3dLathe(*this);
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir sdr::properties::BaseProperties* E3dLatheObj::CreateObjectSpecificProperties()
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     return new sdr::properties::E3dLatheProperties(*this);
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir TYPEINIT1(E3dLatheObj, E3dCompoundObject);
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir /*************************************************************************
68*cdf0e10cSrcweir |*
69*cdf0e10cSrcweir |* Konstruktor aus 3D-Polygon, Scale gibt den Umrechnungsfaktor fuer
70*cdf0e10cSrcweir |* die Koordinaten an
71*cdf0e10cSrcweir |*
72*cdf0e10cSrcweir \************************************************************************/
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir E3dLatheObj::E3dLatheObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon rPoly2D)
75*cdf0e10cSrcweir :   E3dCompoundObject(rDefault),
76*cdf0e10cSrcweir     maPolyPoly2D(rPoly2D)
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
79*cdf0e10cSrcweir     basegfx::B2DHomMatrix aMirrorY;
80*cdf0e10cSrcweir     aMirrorY.scale(1.0, -1.0);
81*cdf0e10cSrcweir     maPolyPoly2D.transform(aMirrorY);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     // Defaults setzen
84*cdf0e10cSrcweir     SetDefaultAttributes(rDefault);
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     // Ueberfluessige Punkte entfernen, insbesondere doppelte
87*cdf0e10cSrcweir     // Start- und Endpunkte verhindern
88*cdf0e10cSrcweir     maPolyPoly2D.removeDoublePoints();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     if(maPolyPoly2D.count())
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
93*cdf0e10cSrcweir         sal_uInt32 nSegCnt(rPoly.count());
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         if(nSegCnt && !rPoly.isClosed())
96*cdf0e10cSrcweir         {
97*cdf0e10cSrcweir             nSegCnt -= 1;
98*cdf0e10cSrcweir         }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt));
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir /*************************************************************************
105*cdf0e10cSrcweir |*
106*cdf0e10cSrcweir |* Leer-Konstruktor
107*cdf0e10cSrcweir |*
108*cdf0e10cSrcweir \************************************************************************/
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir E3dLatheObj::E3dLatheObj()
111*cdf0e10cSrcweir :    E3dCompoundObject()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     // Defaults setzen
114*cdf0e10cSrcweir     E3dDefaultAttributes aDefault;
115*cdf0e10cSrcweir     SetDefaultAttributes(aDefault);
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir void E3dLatheObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
121*cdf0e10cSrcweir     GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
122*cdf0e10cSrcweir     GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode()));
123*cdf0e10cSrcweir     GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront()));
124*cdf0e10cSrcweir     GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack()));
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir /*************************************************************************
128*cdf0e10cSrcweir |*
129*cdf0e10cSrcweir |* Identifier zurueckgeben
130*cdf0e10cSrcweir |*
131*cdf0e10cSrcweir \************************************************************************/
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir sal_uInt16 E3dLatheObj::GetObjIdentifier() const
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     return E3D_LATHEOBJ_ID;
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir /*************************************************************************
139*cdf0e10cSrcweir |*
140*cdf0e10cSrcweir |* Zuweisungsoperator
141*cdf0e10cSrcweir |*
142*cdf0e10cSrcweir \************************************************************************/
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir void E3dLatheObj::operator=(const SdrObject& rObj)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     // erstmal alle Childs kopieren
147*cdf0e10cSrcweir     E3dCompoundObject::operator=(rObj);
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     // weitere Parameter kopieren
150*cdf0e10cSrcweir     const E3dLatheObj& r3DObj = (const E3dLatheObj&)rObj;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     maPolyPoly2D  = r3DObj.maPolyPoly2D;
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir /*************************************************************************
156*cdf0e10cSrcweir |*
157*cdf0e10cSrcweir |* Wandle das Objekt in ein Gruppenobjekt bestehend aus n Polygonen
158*cdf0e10cSrcweir |*
159*cdf0e10cSrcweir \************************************************************************/
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir SdrObject *E3dLatheObj::DoConvertToPolyObj(sal_Bool /*bBezier*/) const
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     return NULL;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir /*************************************************************************
167*cdf0e10cSrcweir |*
168*cdf0e10cSrcweir |* Neue Segmentierung (Beschreibung siehe Header-File)
169*cdf0e10cSrcweir |*
170*cdf0e10cSrcweir \************************************************************************/
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void E3dLatheObj::ReSegment(sal_uInt32 nHSegs, sal_uInt32 nVSegs)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     if ((nHSegs != GetHorizontalSegments() || nVSegs != GetVerticalSegments()) &&
175*cdf0e10cSrcweir         (nHSegs != 0 || nVSegs != 0))
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir         GetProperties().SetObjectItemDirect(Svx3DHorizontalSegmentsItem(nHSegs));
178*cdf0e10cSrcweir         GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nVSegs));
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         ActionChanged();
181*cdf0e10cSrcweir     }
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir /*************************************************************************
185*cdf0e10cSrcweir |*
186*cdf0e10cSrcweir |* Lokale Parameter setzen mit Geometrieneuerzeugung
187*cdf0e10cSrcweir |*
188*cdf0e10cSrcweir \************************************************************************/
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon& rNew)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     if(maPolyPoly2D != rNew)
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         maPolyPoly2D = rNew;
195*cdf0e10cSrcweir         maPolyPoly2D.removeDoublePoints();
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir         if(maPolyPoly2D.count())
198*cdf0e10cSrcweir         {
199*cdf0e10cSrcweir             const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
200*cdf0e10cSrcweir             sal_uInt32 nSegCnt(rPoly.count());
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir             if(nSegCnt && !rPoly.isClosed())
203*cdf0e10cSrcweir             {
204*cdf0e10cSrcweir                 nSegCnt -= 1;
205*cdf0e10cSrcweir             }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir             GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt));
208*cdf0e10cSrcweir         }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         ActionChanged();
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir /*************************************************************************
215*cdf0e10cSrcweir |*
216*cdf0e10cSrcweir |* Get the name of the object (singular)
217*cdf0e10cSrcweir |*
218*cdf0e10cSrcweir \************************************************************************/
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void E3dLatheObj::TakeObjNameSingul(XubString& rName) const
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     rName=ImpGetResStr(STR_ObjNameSingulLathe3d);
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     String aName( GetName() );
225*cdf0e10cSrcweir     if(aName.Len())
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         rName += sal_Unicode(' ');
228*cdf0e10cSrcweir         rName += sal_Unicode('\'');
229*cdf0e10cSrcweir         rName += aName;
230*cdf0e10cSrcweir         rName += sal_Unicode('\'');
231*cdf0e10cSrcweir     }
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir /*************************************************************************
235*cdf0e10cSrcweir |*
236*cdf0e10cSrcweir |* Get the name of the object (plural)
237*cdf0e10cSrcweir |*
238*cdf0e10cSrcweir \************************************************************************/
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void E3dLatheObj::TakeObjNamePlural(XubString& rName) const
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     rName=ImpGetResStr(STR_ObjNamePluralLathe3d);
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir /*************************************************************************
246*cdf0e10cSrcweir |*
247*cdf0e10cSrcweir |* Aufbrechen
248*cdf0e10cSrcweir |*
249*cdf0e10cSrcweir \************************************************************************/
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir sal_Bool E3dLatheObj::IsBreakObjPossible()
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     return sal_True;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir SdrAttrObj* E3dLatheObj::GetBreakObj()
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     // create PathObj
259*cdf0e10cSrcweir     basegfx::B3DPolyPolygon aLathePoly3D(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D));
260*cdf0e10cSrcweir     basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
261*cdf0e10cSrcweir     SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aTransPoly);
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     if(pPathObj)
264*cdf0e10cSrcweir     {
265*cdf0e10cSrcweir         // Attribute setzen
266*cdf0e10cSrcweir         SfxItemSet aSet(GetObjectItemSet());
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir         // Linien aktivieren, um Objekt garantiert sichtbar zu machen
269*cdf0e10cSrcweir         aSet.Put(XLineStyleItem(XLINE_SOLID));
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir         pPathObj->SetMergedItemSet(aSet);
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     return pPathObj;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // eof
278