xref: /trunk/main/svx/source/engine3d/sphere3d.cxx (revision a5b190bfa3e1bed4623e2958a8877664a3b5506c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include "svx/svdstr.hrc"
32 #include "svx/svdglob.hxx"
33 #include <svx/svdmodel.hxx>
34 #include <svx/svdpage.hxx>
35 #include "svx/globl3d.hxx"
36 #include <svx/sphere3d.hxx>
37 
38 #include <svx/svxids.hrc>
39 #include <svx/svx3ditems.hxx>
40 #include <svx/sdr/properties/e3dsphereproperties.hxx>
41 #include <basegfx/vector/b3dvector.hxx>
42 #include <basegfx/point/b3dpoint.hxx>
43 #include <svx/sdr/contact/viewcontactofe3dsphere.hxx>
44 #include <basegfx/polygon/b3dpolygon.hxx>
45 
46 //////////////////////////////////////////////////////////////////////////////
47 // #110094# DrawContact section
48 
49 sdr::contact::ViewContact* E3dSphereObj::CreateObjectSpecificViewContact()
50 {
51     return new sdr::contact::ViewContactOfE3dSphere(*this);
52 }
53 
54 //////////////////////////////////////////////////////////////////////////////
55 
56 sdr::properties::BaseProperties* E3dSphereObj::CreateObjectSpecificProperties()
57 {
58     return new sdr::properties::E3dSphereProperties(*this);
59 }
60 
61 //////////////////////////////////////////////////////////////////////////////
62 
63 TYPEINIT1(E3dSphereObj, E3dCompoundObject);
64 
65 /*************************************************************************
66 |*
67 |* Kugel aus Polygonfacetten nach Laengen und Breitengrad aufbauen
68 |*
69 \************************************************************************/
70 
71 E3dSphereObj::E3dSphereObj(E3dDefaultAttributes& rDefault, const basegfx::B3DPoint& rCenter, const basegfx::B3DVector& r3DSize)
72 :   E3dCompoundObject(rDefault)
73 {
74     // Defaults setzen
75     SetDefaultAttributes(rDefault);
76 
77     // Uebergebene drueberbuegeln
78     aCenter = rCenter;
79     aSize = r3DSize;
80 }
81 
82 E3dSphereObj::E3dSphereObj()
83 :   E3dCompoundObject()
84 {
85     // Defaults setzen
86     E3dDefaultAttributes aDefault;
87     SetDefaultAttributes(aDefault);
88 }
89 
90 /*************************************************************************
91 |*
92 |* Kugel erzeugen ohne die Polygone darin zu erzeugen
93 |*
94 \************************************************************************/
95 
96 // FG: Dieser Aufruf erfolgt von der 3D-Object Factory (objfac3d.cxx) und zwar ausschliesslich beim
97 //     laden von Dokumenten. Hier braucht man keinen CreateSphere-Aufruf, denn die wirkliche
98 //     Anzahl Segmente ist ja noch nicht bekannt. Dies war bis zum 10.2.97 ein (kleines)
99 //     Speicherleck.
100 E3dSphereObj::E3dSphereObj(int /*dummy*/) // den Parameter braucht es um unterscheiden zu koennen, welcher
101 {                                     // der beiden Konstruktoren gemeint ist. Der obige halt per Default
102     // Defaults setzen
103     E3dDefaultAttributes aDefault;
104     SetDefaultAttributes(aDefault);
105 }
106 
107 void E3dSphereObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
108 {
109     // Defaults setzen
110     aCenter = rDefault.GetDefaultSphereCenter();
111     aSize = rDefault.GetDefaultSphereSize();
112 }
113 
114 /*************************************************************************
115 |*
116 |* Identifier zurueckgeben
117 |*
118 \************************************************************************/
119 
120 sal_uInt16 E3dSphereObj::GetObjIdentifier() const
121 {
122     return E3D_SPHEREOBJ_ID;
123 }
124 
125 /*************************************************************************
126 |*
127 |* Wandle das Objekt in ein Gruppenobjekt bestehend aus n Polygonen
128 |*
129 \************************************************************************/
130 
131 SdrObject *E3dSphereObj::DoConvertToPolyObj(sal_Bool /*bBezier*/, bool /*bAddText*/) const
132 {
133     return NULL;
134 }
135 
136 /*************************************************************************
137 |*
138 |* Leer-Konstruktor
139 |*
140 \************************************************************************/
141 
142 void E3dSphereObj::ReSegment(sal_uInt32 nHSegs, sal_uInt32 nVSegs)
143 {
144     if((nHSegs != GetHorizontalSegments() || nVSegs != GetVerticalSegments()) && (nHSegs != 0 || nVSegs != 0))
145     {
146         GetProperties().SetObjectItemDirect(Svx3DHorizontalSegmentsItem(nHSegs));
147         GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nVSegs));
148 
149         ActionChanged();
150     }
151 }
152 
153 /*************************************************************************
154 |*
155 |* Zuweisungsoperator
156 |*
157 \************************************************************************/
158 
159 void E3dSphereObj::operator=(const SdrObject& rObj)
160 {
161     // erstmal alle Childs kopieren
162     E3dCompoundObject::operator=(rObj);
163 
164     // weitere Parameter kopieren
165     const E3dSphereObj& r3DObj = (const E3dSphereObj&) rObj;
166 
167     aCenter       = r3DObj.aCenter;
168     aSize         = r3DObj.aSize;
169 }
170 
171 /*************************************************************************
172 |*
173 |* Lokale Parameter setzen mit Geometrieneuerzeugung
174 |*
175 \************************************************************************/
176 
177 void E3dSphereObj::SetCenter(const basegfx::B3DPoint& rNew)
178 {
179     if(aCenter != rNew)
180     {
181         aCenter = rNew;
182         ActionChanged();
183     }
184 }
185 
186 void E3dSphereObj::SetSize(const basegfx::B3DVector& rNew)
187 {
188     if(aSize != rNew)
189     {
190         aSize = rNew;
191         ActionChanged();
192     }
193 }
194 
195 /*************************************************************************
196 |*
197 |* Get the name of the object (singular)
198 |*
199 \************************************************************************/
200 
201 void E3dSphereObj::TakeObjNameSingul(XubString& rName) const
202 {
203     rName=ImpGetResStr(STR_ObjNameSingulSphere3d);
204 
205     String aName( GetName() );
206     if(aName.Len())
207     {
208         rName += sal_Unicode(' ');
209         rName += sal_Unicode('\'');
210         rName += aName;
211         rName += sal_Unicode('\'');
212     }
213 }
214 
215 /*************************************************************************
216 |*
217 |* Get the name of the object (plural)
218 |*
219 \************************************************************************/
220 
221 void E3dSphereObj::TakeObjNamePlural(XubString& rName) const
222 {
223     rName=ImpGetResStr(STR_ObjNamePluralSphere3d);
224 }
225 
226 // eof
227