Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "svx/svdstr.hrc"
22 : #include "svx/svdglob.hxx"
23 : #include <tools/poly.hxx>
24 : #include <svx/svdpage.hxx>
25 : #include "svx/globl3d.hxx"
26 : #include <svx/lathe3d.hxx>
27 : #include <svx/xpoly.hxx>
28 : #include <svx/svxids.hrc>
29 : #include <svx/svdopath.hxx>
30 : #include <svx/svdmodel.hxx>
31 : #include <svx/svx3ditems.hxx>
32 : #include <svx/sdr/properties/e3dlatheproperties.hxx>
33 : #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
34 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
35 : #include <basegfx/polygon/b2dpolygontools.hxx>
36 : #include <basegfx/matrix/b2dhommatrix.hxx>
37 :
38 : //////////////////////////////////////////////////////////////////////////////
39 : // DrawContact section
40 :
41 0 : sdr::contact::ViewContact* E3dLatheObj::CreateObjectSpecificViewContact()
42 : {
43 0 : return new sdr::contact::ViewContactOfE3dLathe(*this);
44 : }
45 :
46 : //////////////////////////////////////////////////////////////////////////////
47 :
48 0 : sdr::properties::BaseProperties* E3dLatheObj::CreateObjectSpecificProperties()
49 : {
50 0 : return new sdr::properties::E3dLatheProperties(*this);
51 : }
52 :
53 : //////////////////////////////////////////////////////////////////////////////
54 :
55 3601 : TYPEINIT1(E3dLatheObj, E3dCompoundObject);
56 :
57 : // Constructor from 3D polygon, scale is the conversion factor for the coordinates
58 :
59 0 : E3dLatheObj::E3dLatheObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon rPoly2D)
60 : : E3dCompoundObject(rDefault),
61 0 : maPolyPoly2D(rPoly2D)
62 : {
63 : // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
64 0 : basegfx::B2DHomMatrix aMirrorY;
65 0 : aMirrorY.scale(1.0, -1.0);
66 0 : maPolyPoly2D.transform(aMirrorY);
67 :
68 : // Set Defaults
69 0 : SetDefaultAttributes(rDefault);
70 :
71 : // Superfluous items removed, in particular to prevent duplicate
72 : // start and end points
73 0 : maPolyPoly2D.removeDoublePoints();
74 :
75 0 : if(maPolyPoly2D.count())
76 : {
77 0 : const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
78 0 : sal_uInt32 nSegCnt(rPoly.count());
79 :
80 0 : if(nSegCnt && !rPoly.isClosed())
81 : {
82 0 : nSegCnt -= 1;
83 : }
84 :
85 0 : GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt));
86 0 : }
87 0 : }
88 :
89 0 : E3dLatheObj::E3dLatheObj()
90 0 : : E3dCompoundObject()
91 : {
92 : // Set Defaults
93 0 : E3dDefaultAttributes aDefault;
94 0 : SetDefaultAttributes(aDefault);
95 0 : }
96 :
97 0 : void E3dLatheObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
98 : {
99 0 : GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
100 0 : GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
101 0 : GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode()));
102 0 : GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront()));
103 0 : GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack()));
104 0 : }
105 :
106 0 : sal_uInt16 E3dLatheObj::GetObjIdentifier() const
107 : {
108 0 : return E3D_LATHEOBJ_ID;
109 : }
110 :
111 0 : E3dLatheObj* E3dLatheObj::Clone() const
112 : {
113 0 : return CloneHelper< E3dLatheObj >();
114 : }
115 :
116 : // Convert the object to group object consisting of n polygons
117 :
118 0 : SdrObject *E3dLatheObj::DoConvertToPolyObj(sal_Bool /*bBezier*/, bool /*bAddText*/) const
119 : {
120 0 : return NULL;
121 : }
122 :
123 : // Set Local parameters set to re-create geometry
124 :
125 0 : void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon& rNew)
126 : {
127 0 : if(maPolyPoly2D != rNew)
128 : {
129 0 : maPolyPoly2D = rNew;
130 0 : maPolyPoly2D.removeDoublePoints();
131 :
132 0 : if(maPolyPoly2D.count())
133 : {
134 0 : const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
135 0 : sal_uInt32 nSegCnt(rPoly.count());
136 :
137 0 : if(nSegCnt && !rPoly.isClosed())
138 : {
139 0 : nSegCnt -= 1;
140 : }
141 :
142 0 : GetProperties().SetObjectItemDirect(Svx3DVerticalSegmentsItem(nSegCnt));
143 : }
144 :
145 0 : ActionChanged();
146 : }
147 0 : }
148 :
149 : // Get the name of the object (singular)
150 :
151 0 : void E3dLatheObj::TakeObjNameSingul(XubString& rName) const
152 : {
153 0 : rName=ImpGetResStr(STR_ObjNameSingulLathe3d);
154 :
155 0 : String aName( GetName() );
156 0 : if(aName.Len())
157 : {
158 0 : rName += sal_Unicode(' ');
159 0 : rName += sal_Unicode('\'');
160 0 : rName += aName;
161 0 : rName += sal_Unicode('\'');
162 0 : }
163 0 : }
164 :
165 : // Get the name of the object (plural)
166 :
167 0 : void E3dLatheObj::TakeObjNamePlural(XubString& rName) const
168 : {
169 0 : rName=ImpGetResStr(STR_ObjNamePluralLathe3d);
170 0 : }
171 :
172 0 : sal_Bool E3dLatheObj::IsBreakObjPossible()
173 : {
174 0 : return sal_True;
175 : }
176 :
177 0 : SdrAttrObj* E3dLatheObj::GetBreakObj()
178 : {
179 : // create PathObj
180 0 : basegfx::B3DPolyPolygon aLathePoly3D(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D));
181 0 : basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
182 0 : SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aTransPoly);
183 :
184 0 : if(pPathObj)
185 : {
186 : // Set Attribute
187 0 : SfxItemSet aSet(GetObjectItemSet());
188 :
189 : // Enable lines to guarantee that the object becomes visible
190 0 : aSet.Put(XLineStyleItem(XLINE_SOLID));
191 :
192 0 : pPathObj->SetMergedItemSet(aSet);
193 : }
194 :
195 0 : return pPathObj;
196 : }
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|