/src/libreoffice/svx/source/engine3d/lathe3d.cxx
Line | Count | Source (jump to first uncovered line) |
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/deflt3d.hxx> |
22 | | #include <svx/strings.hrc> |
23 | | #include <svx/dialmgr.hxx> |
24 | | #include <svx/svdobjkind.hxx> |
25 | | #include <svx/lathe3d.hxx> |
26 | | #include <svx/svdopath.hxx> |
27 | | #include <svx/svdmodel.hxx> |
28 | | #include <svx/svx3ditems.hxx> |
29 | | #include <svx/xlineit0.hxx> |
30 | | #include <sdr/properties/e3dlatheproperties.hxx> |
31 | | #include <sdr/contact/viewcontactofe3dlathe.hxx> |
32 | | #include <basegfx/polygon/b2dpolypolygontools.hxx> |
33 | | #include <basegfx/matrix/b2dhommatrix.hxx> |
34 | | #include <utility> |
35 | | |
36 | | |
37 | | // DrawContact section |
38 | | std::unique_ptr<sdr::contact::ViewContact> E3dLatheObj::CreateObjectSpecificViewContact() |
39 | 0 | { |
40 | 0 | return std::make_unique<sdr::contact::ViewContactOfE3dLathe>(*this); |
41 | 0 | } |
42 | | |
43 | | std::unique_ptr<sdr::properties::BaseProperties> E3dLatheObj::CreateObjectSpecificProperties() |
44 | 0 | { |
45 | 0 | return std::make_unique<sdr::properties::E3dLatheProperties>(*this); |
46 | 0 | } |
47 | | |
48 | | // Constructor from 3D polygon, scale is the conversion factor for the coordinates |
49 | | E3dLatheObj::E3dLatheObj( |
50 | | SdrModel& rSdrModel, |
51 | | const E3dDefaultAttributes& rDefault, |
52 | | basegfx::B2DPolyPolygon aPoly2D) |
53 | 0 | : E3dCompoundObject(rSdrModel), |
54 | 0 | maPolyPoly2D(std::move(aPoly2D)) |
55 | 0 | { |
56 | | // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here |
57 | 0 | basegfx::B2DHomMatrix aMirrorY; |
58 | 0 | aMirrorY.scale(1.0, -1.0); |
59 | 0 | maPolyPoly2D.transform(aMirrorY); |
60 | | |
61 | | // Set Defaults |
62 | 0 | SetDefaultAttributes(rDefault); |
63 | | |
64 | | // Superfluous items removed, in particular to prevent duplicate |
65 | | // start and end points |
66 | 0 | maPolyPoly2D.removeDoublePoints(); |
67 | |
|
68 | 0 | if(maPolyPoly2D.count()) |
69 | 0 | { |
70 | 0 | const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0)); |
71 | 0 | sal_uInt32 nSegCnt(rPoly.count()); |
72 | |
|
73 | 0 | if(nSegCnt && !rPoly.isClosed()) |
74 | 0 | { |
75 | 0 | nSegCnt -= 1; |
76 | 0 | } |
77 | |
|
78 | 0 | GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt)); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel) |
83 | 0 | : E3dCompoundObject(rSdrModel) |
84 | 0 | { |
85 | | // Set Defaults |
86 | 0 | const E3dDefaultAttributes aDefault; |
87 | |
|
88 | 0 | SetDefaultAttributes(aDefault); |
89 | 0 | } |
90 | | |
91 | | E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel, E3dLatheObj const & rSource) |
92 | 0 | : E3dCompoundObject(rSdrModel, rSource) |
93 | 0 | { |
94 | | // Set Defaults |
95 | 0 | const E3dDefaultAttributes aDefault; |
96 | |
|
97 | 0 | SetDefaultAttributes(aDefault); |
98 | |
|
99 | 0 | maPolyPoly2D = rSource.maPolyPoly2D; |
100 | 0 | } |
101 | | |
102 | | E3dLatheObj::~E3dLatheObj() |
103 | 0 | { |
104 | 0 | } |
105 | | |
106 | | void E3dLatheObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault) |
107 | 0 | { |
108 | 0 | GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed())); |
109 | 0 | GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack())); |
110 | 0 | GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode())); |
111 | 0 | GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront())); |
112 | 0 | GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack())); |
113 | 0 | } |
114 | | |
115 | | SdrObjKind E3dLatheObj::GetObjIdentifier() const |
116 | 0 | { |
117 | 0 | return SdrObjKind::E3D_Lathe; |
118 | 0 | } |
119 | | |
120 | | rtl::Reference<SdrObject> E3dLatheObj::CloneSdrObject(SdrModel& rTargetModel) const |
121 | 0 | { |
122 | 0 | return new E3dLatheObj(rTargetModel, *this); |
123 | 0 | } |
124 | | |
125 | | // Convert the object to group object consisting of n polygons |
126 | | |
127 | | rtl::Reference<SdrObject> E3dLatheObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const |
128 | 0 | { |
129 | 0 | return nullptr; |
130 | 0 | } |
131 | | |
132 | | // Set Local parameters set to re-create geometry |
133 | | |
134 | | void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon& rNew) |
135 | 0 | { |
136 | 0 | if(maPolyPoly2D == rNew) |
137 | 0 | return; |
138 | | |
139 | 0 | maPolyPoly2D = rNew; |
140 | 0 | maPolyPoly2D.removeDoublePoints(); |
141 | |
|
142 | 0 | if(maPolyPoly2D.count()) |
143 | 0 | { |
144 | 0 | const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0)); |
145 | 0 | sal_uInt32 nSegCnt(rPoly.count()); |
146 | |
|
147 | 0 | if(nSegCnt && !rPoly.isClosed()) |
148 | 0 | { |
149 | 0 | nSegCnt -= 1; |
150 | 0 | } |
151 | |
|
152 | 0 | GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt)); |
153 | 0 | } |
154 | |
|
155 | 0 | ActionChanged(); |
156 | 0 | } |
157 | | |
158 | | // Get the name of the object (singular) |
159 | | |
160 | | OUString E3dLatheObj::TakeObjNameSingul() const |
161 | 0 | { |
162 | 0 | OUString sName(SvxResId(STR_ObjNameSingulLathe3d)); |
163 | |
|
164 | 0 | OUString aName(GetName()); |
165 | 0 | if (!aName.isEmpty()) |
166 | 0 | { |
167 | 0 | sName += " '" + aName + "'"; |
168 | 0 | } |
169 | 0 | return sName; |
170 | 0 | } |
171 | | |
172 | | // Get the name of the object (plural) |
173 | | |
174 | | OUString E3dLatheObj::TakeObjNamePlural() const |
175 | 0 | { |
176 | 0 | return SvxResId(STR_ObjNamePluralLathe3d); |
177 | 0 | } |
178 | | |
179 | | bool E3dLatheObj::IsBreakObjPossible() |
180 | 0 | { |
181 | 0 | return true; |
182 | 0 | } |
183 | | |
184 | | rtl::Reference<SdrAttrObj> E3dLatheObj::GetBreakObj() |
185 | 0 | { |
186 | | // create PathObj |
187 | 0 | basegfx::B3DPolyPolygon aLathePoly3D(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D)); |
188 | 0 | basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D)); |
189 | 0 | rtl::Reference<SdrPathObj> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), SdrObjKind::PolyLine, std::move(aTransPoly))); |
190 | | |
191 | | // Set Attribute |
192 | 0 | SfxItemSet aSet(GetObjectItemSet()); |
193 | | |
194 | | // Enable lines to guarantee that the object becomes visible |
195 | 0 | aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID)); |
196 | |
|
197 | 0 | pPathObj->SetMergedItemSet(aSet); |
198 | |
|
199 | 0 | return pPathObj; |
200 | 0 | } |
201 | | |
202 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |