1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/*
**************************************************************************
description
--------------------
copyright : (C) 2000-2002 by Andreas Zehender
email : zehender@kde.org
**************************************************************************
**************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
**************************************************************************/
#include "pmgraphicalobject.h"
#include "pmxmlhelper.h"
#include "pmmemento.h"
const bool c_defaultNoShadow = false;
const bool c_defaultNoImage = false;
const bool c_defaultNoReflection = false;
const bool c_defaultDoubleIlluminate = false;
const int c_defaultVisibilityLevel = 0;
const bool c_defaultRelativeVisibility = true;
const bool c_defaultExport = true;
PMDefinePropertyClass( PMGraphicalObject, PMGraphicalObjectProperty );
PMMetaObject* PMGraphicalObject::s_pMetaObject = 0;
PMGraphicalObject::PMGraphicalObject( PMPart* part )
: Base( part )
{
m_noShadow = c_defaultNoShadow;
m_noImage = c_defaultNoImage;
m_noReflection = c_defaultNoReflection;
m_doubleIlluminate = c_defaultDoubleIlluminate;
m_visibilityLevel = c_defaultVisibilityLevel;
m_relativeVisibility = c_defaultRelativeVisibility;
m_export = c_defaultExport;
}
PMGraphicalObject::PMGraphicalObject( const PMGraphicalObject& o )
: Base( o )
{
m_noShadow = o.m_noShadow;
m_noImage = o.m_noImage;
m_noReflection = o.m_noReflection;
m_doubleIlluminate = o.m_doubleIlluminate;
m_visibilityLevel = o.m_visibilityLevel;
m_relativeVisibility = o.m_relativeVisibility;
m_export = o.m_export;
}
PMGraphicalObject::~PMGraphicalObject( )
{
}
PMMetaObject* PMGraphicalObject::metaObject( ) const
{
if( !s_pMetaObject )
{
s_pMetaObject = new PMMetaObject( "GraphicalObject", Base::metaObject( ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "noShadow", &PMGraphicalObject::setNoShadow,
&PMGraphicalObject::noShadow ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "noImage", &PMGraphicalObject::setNoImage,
&PMGraphicalObject::noImage ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "noReflection", &PMGraphicalObject::setNoReflection,
&PMGraphicalObject::noReflection ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "doubleIlluminate", &PMGraphicalObject::setDoubleIlluminate,
&PMGraphicalObject::doubleIlluminate ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "visibilityLevel", &PMGraphicalObject::setVisibilityLevel,
&PMGraphicalObject::visibilityLevel ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "relativeVisibilityLevel", &PMGraphicalObject::setVisibilityLevelRelative,
&PMGraphicalObject::isVisibilityLevelRelative ) );
s_pMetaObject->addProperty(
new PMGraphicalObjectProperty( "export", &PMGraphicalObject::setExportPovray,
&PMGraphicalObject::exportPovray ) );
}
return s_pMetaObject;
}
void PMGraphicalObject::cleanUp( ) const
{
if( s_pMetaObject )
{
delete s_pMetaObject;
s_pMetaObject = 0;
}
Base::cleanUp( );
}
void PMGraphicalObject::serialize( QDomElement& e, QDomDocument& doc ) const
{
e.setAttribute( "no_shadow", m_noShadow );
e.setAttribute( "no_image", m_noImage );
e.setAttribute( "no_reflection", m_noReflection );
e.setAttribute( "double_illuminate", m_doubleIlluminate );
e.setAttribute( "visibility_level", m_visibilityLevel );
e.setAttribute( "relative_visibility", m_relativeVisibility );
e.setAttribute( "export", m_export );
Base::serialize( e, doc );
}
void PMGraphicalObject::readAttributes( const PMXMLHelper& h )
{
m_noShadow = h.boolAttribute( "no_shadow", c_defaultNoShadow );
m_noImage = h.boolAttribute( "no_image", c_defaultNoImage );
m_noReflection = h.boolAttribute( "no_reflection", c_defaultNoReflection );
m_doubleIlluminate = h.boolAttribute( "double_illuminate",
c_defaultDoubleIlluminate );
m_visibilityLevel = h.intAttribute( "visibility_level",
c_defaultVisibilityLevel );
m_relativeVisibility = h.boolAttribute( "relative_visibility",
c_defaultRelativeVisibility );
m_export = h.boolAttribute( "export", c_defaultExport );
Base::readAttributes( h );
}
void PMGraphicalObject::setNoShadow( bool yes )
{
if( m_noShadow != yes )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMNoShadowID, m_noShadow );
m_noShadow = yes;
}
}
void PMGraphicalObject::setNoImage( bool yes )
{
if( m_noImage != yes )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMNoImageID, m_noImage );
m_noImage = yes;
}
}
void PMGraphicalObject::setNoReflection( bool yes )
{
if ( m_noReflection != yes )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMNoReflectionID, m_noReflection );
m_noReflection = yes;
}
}
void PMGraphicalObject::setDoubleIlluminate( bool yes )
{
if( m_doubleIlluminate != yes )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMDoubleIlluminateID, m_doubleIlluminate );
m_doubleIlluminate = yes;
}
}
void PMGraphicalObject::setVisibilityLevel( int level )
{
if( m_visibilityLevel != level )
{
if( m_pMemento )
{
m_pMemento->addData( s_pMetaObject, PMVisibilityID,
m_visibilityLevel );
// do not call PMCompositeObject::setViewStructureChanged because
// the view structure has not really changed.
// Only the scene has to be rendered.
m_pMemento->setViewStructureChanged( );
}
m_visibilityLevel = level;
}
}
void PMGraphicalObject::setVisibilityLevelRelative( bool relative )
{
if( m_relativeVisibility != relative )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMRelativeVisibilityID,
m_relativeVisibility );
m_relativeVisibility = relative;
}
}
void PMGraphicalObject::setExportPovray( bool ex )
{
if( m_export != ex )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMExportID, m_export );
m_export = ex;
}
}
void PMGraphicalObject::restoreMemento( PMMemento* s )
{
PMMementoDataIterator it( s );
PMMementoData* data;
for( ; it.current( ); ++it )
{
data = it.current( );
if( data->objectType( ) == s_pMetaObject )
{
switch( data->valueID( ) )
{
case PMNoShadowID:
setNoShadow( data->boolData( ) );
break;
case PMNoImageID:
setNoImage( data->boolData( ) );
break;
case PMNoReflectionID:
setNoReflection( data->boolData( ) );
break;
case PMDoubleIlluminateID:
setDoubleIlluminate( data->boolData( ) );
break;
case PMVisibilityID:
setVisibilityLevel( data->intData( ) );
break;
case PMRelativeVisibilityID:
setVisibilityLevelRelative( data->boolData( ) );
break;
case PMExportID:
setExportPovray( data->boolData( ) );
break;
default:
kdError( PMArea ) << "Wrong ID in PMGraphicalObject::restoreMemento\n";
break;
}
}
}
Base::restoreMemento( s );
}
|