summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmnormal.cpp
blob: 05ec9bcd76c8b8760585c08d99867eb419fd4efd (plain)
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
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Luis Carvalho
    email                : lpassos@mail.telepac.pt
**************************************************************************

**************************************************************************
*                                                                        *
*  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 "pmnormal.h"
#include "pmxmlhelper.h"
#include "pmmemento.h"
#include "pmnormaledit.h"
#include "pmlistpattern.h"
#include "pmpattern.h"

#include <tdelocale.h>

const double bumpSizeDefault = 0.0;
const double accuracyDefault = 0.02;

PMDefinePropertyClass( PMNormal, PMNormProperty );

PMMetaObject* PMNormal::s_pMetaObject = 0;
PMObject* createNewNormal( PMPart* part )
{
   return new PMNormal( part );
}

PMNormal::PMNormal( PMPart* part )
      : Base( part )
{
   m_enableBumpSize = false;
   m_bumpSize = bumpSizeDefault;
   m_accuracy = accuracyDefault;
   m_uvMapping = false;
}

PMNormal::PMNormal( const PMNormal& n )
      : Base( n )
{
   m_enableBumpSize = n.m_enableBumpSize;
   m_bumpSize = n.m_bumpSize;
   m_accuracy = n.m_accuracy;
   m_uvMapping = n.m_uvMapping;
}

PMNormal::~PMNormal( )
{
}

PMMetaObject* PMNormal::metaObject( ) const
{
   if( !s_pMetaObject )
   {
      s_pMetaObject = new PMMetaObject( "Normal", Base::metaObject( ),
                                        createNewNormal );
      s_pMetaObject->addProperty(
         new PMNormProperty( "bumpSize", &PMNormal::setBumpSize, &PMNormal::bumpSize ) );
      s_pMetaObject->addProperty(
         new PMNormProperty( "bumpSizeEnabled", &PMNormal::enableBumpSize, &PMNormal::isBumpSizeEnabled ) );
      s_pMetaObject->addProperty(
         new PMNormProperty( "accuracy", &PMNormal::setAccuracy, &PMNormal::accuracy ) );
      s_pMetaObject->addProperty(
         new PMNormProperty( "uvMapping", &PMNormal::setUVMapping, &PMNormal::uvMapping ) );
   }
   return s_pMetaObject;
}

void PMNormal::cleanUp( ) const
{
   if( s_pMetaObject )
   {
      delete s_pMetaObject;
      s_pMetaObject = 0;
   }
   Base::cleanUp( );
}

TQString PMNormal::description( ) const
{
   return i18n( "normal" );
}

void PMNormal::serialize( TQDomElement& e, TQDomDocument& doc ) const
{
   Base::serialize( e, doc );
   e.setAttribute( "enable_bump_size", m_enableBumpSize );
   e.setAttribute( "bump_size", m_bumpSize );
   e.setAttribute( "accuracy", m_accuracy );
   e.setAttribute( "uv_mapping", m_uvMapping );
}

void PMNormal::readAttributes( const PMXMLHelper& h )
{
   Base::readAttributes( h );
   m_enableBumpSize = h.boolAttribute( "enable_bump_size", false );
   m_bumpSize = h.doubleAttribute( "bump_size", bumpSizeDefault );
   m_accuracy = h.doubleAttribute( "accuracy", accuracyDefault );
   m_uvMapping = h.boolAttribute( "uv_mapping", false );
}

PMDialogEditBase* PMNormal::editWidget( TQWidget* parent ) const
{
   return new PMNormalEdit( parent );
}

void PMNormal::enableBumpSize( bool c )
{
   if( c != m_enableBumpSize )
   {
      if( m_pMemento )
         m_pMemento->addData( s_pMetaObject, PMEnableBumpSizeID, m_enableBumpSize );
      m_enableBumpSize = c;
   }
}

void PMNormal::setBumpSize( double c )
{
   if( c != m_bumpSize )
   {
      if( m_pMemento )
         m_pMemento->addData( s_pMetaObject, PMBumpSizeID, m_bumpSize );
      m_bumpSize = c;
   }
}

void PMNormal::setAccuracy( double c )
{
   if( c!= m_accuracy )
   {
      if ( m_pMemento )
         m_pMemento->addData( s_pMetaObject, PMAccuracyID, m_accuracy );
      m_accuracy = c;
   }
}

void PMNormal::setUVMapping( bool m )
{
   if( m != m_uvMapping )
   {
      if ( m_pMemento )
         m_pMemento->addData( s_pMetaObject, PMUVMappingID, m_uvMapping );
      m_uvMapping = m;
   }
}

void PMNormal::restoreMemento( PMMemento* s )
{
   PMMementoDataIterator it( s );
   PMMementoData* data;

   for( ; it.current( ); ++it )
   {
      data = it.current( );
      if( data->objectType( ) == s_pMetaObject )
      {
         switch( data->valueID( ) )
         {
            case PMEnableBumpSizeID:
               enableBumpSize( data->boolData( ) );
               break;
            case PMBumpSizeID:
               setBumpSize( data->doubleData( ) );
               break;
            case PMAccuracyID:
               setAccuracy( data->doubleData( ) );
               break;
            case PMUVMappingID:
               setUVMapping( data->boolData( ) );
               break;
            default:
               kdError( PMArea ) << "Wrong ID in PMNormal::restoreMemento\n";
               break;
         }
      }
   }
   Base::restoreMemento( s );
}