1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdgeorgesconvert.h"
19 #include "georges_loader.h"
20 #include "mold_elt_define.h"
21 #include "mold_elt_type.h"
22 #include "item_elt_atom.h"
23 #include "item_elt_struct.h"
24 #include "item_elt_list.h"
27 namespace NLOLDGEORGES
30 //////////////////////////////////////////////////////////////////////
31 // Construction/Destruction
32 //////////////////////////////////////////////////////////////////////
37 // pitemelparents = 0;
38 // pitemeacomments = 0;
54 delete( pitemelparents );
57 delete( pitemeacomments );
62 void CItem::SetLoader( CLoader
* const _pl
)
68 void CItem::Load( const CStringEx
& _sxfullname
)
73 CForm form
, formcurrent
, formparent
;
74 pl
->LoadForm( formcurrent
, _sxfullname
);
78 CStringEx sxparent
= formcurrent
.GetParent( 0 );
79 CStringEx sxactivity
= formcurrent
.GetActivity( 0 );
80 while( !sxparent
.empty() )
82 vsxparents
.push_back( std::make_pair( sxactivity
, sxparent
) );
83 if( sxactivity
== "true" )
85 pl
->LoadSearchForm( form
, sxparent
);
89 sxparent
= formcurrent
.GetParent( i
);
90 sxactivity
= formcurrent
.GetActivity( i
);
93 // Find the name of the dfn file
94 int ipos
= _sxfullname
.reverse_find('.');
97 moldfilename
= _sxfullname
.get_right(_sxfullname
.length()-ipos
-1);
98 moldfilename
+= ".dfn";
100 // Load the mold and build the item's tree
101 CMoldElt
* pme
= pl
->LoadMold( moldfilename
);
102 CMoldEltDefine
* pmed
= dynamic_cast< CMoldEltDefine
* >( pme
);
104 pitemes
= new CItemEltStruct( pl
);
105 pitemes
->BuildItem( pmed
);
107 // Fill the tree with parents' form fields
108 pitemes
->FillParent( formparent
.GetBody() );
110 // Fill the tree with current's form
111 pitemes
->FillCurrent( formcurrent
.GetBody() );
114 // Convert CItem to a CForm (in is this)
115 void CItem::MakeForm (CForm
&out
)
119 pitemes
->BuildForm( out
.GetBody(), vsxparents
);
122 // Convert CForm to CItem (out is this)
123 void CItem::MakeItem (CForm
&in
)
125 CForm form
, formparent
;
129 CStringEx sxparent
= in
.GetParent( 0 );
130 CStringEx sxactivity
= in
.GetActivity( 0 );
131 while( !sxparent
.empty() )
133 vsxparents
.push_back( std::make_pair( sxactivity
, sxparent
) );
134 if( sxactivity
== "true" )
136 pl
->LoadSearchForm( form
, sxparent
);
140 sxparent
= in
.GetParent( i
);
141 sxactivity
= in
.GetActivity( i
);
144 CMoldElt
* pme
= pl
->LoadMold( moldfilename
);
145 CMoldEltDefine
* pmed
= dynamic_cast< CMoldEltDefine
* >( pme
);
147 pitemes
= new CItemEltStruct( pl
);
148 pitemes
->BuildItem( pmed
);
150 pitemes
->FillParent( formparent
.GetBody() );
151 pitemes
->FillCurrent( in
.GetBody() );
154 void CItem::VirtualSaveLoad()
159 CForm form
, formcurrent
, formparent
;
160 pitemes
->BuildForm( formcurrent
.GetBody(), vsxparents
);
164 CStringEx sxparent
= formcurrent
.GetParent( 0 );
165 CStringEx sxactivity
= formcurrent
.GetActivity( 0 );
166 while( !sxparent
.empty() )
168 vsxparents
.push_back( std::make_pair( sxactivity
, sxparent
) );
169 if( sxactivity
== "true" )
171 pl
->LoadSearchForm( form
, sxparent
);
175 sxparent
= formcurrent
.GetParent( i
);
176 sxactivity
= formcurrent
.GetActivity( i
);
179 CMoldElt
* pme
= pl
->LoadMold( moldfilename
);
180 CMoldEltDefine
* pmed
= dynamic_cast< CMoldEltDefine
* >( pme
);
182 pitemes
= new CItemEltStruct( pl
);
183 pitemes
->BuildItem( pmed
);
185 pitemes
->FillParent( formparent
.GetBody() );
186 pitemes
->FillCurrent( formcurrent
.GetBody() );
189 void CItem::New( const CStringEx
& _sxdfnfilename
)
193 moldfilename
= _sxdfnfilename
;
195 CMoldElt
* pme
= pl
->LoadMold( _sxdfnfilename
);
196 CMoldEltDefine
* pmed
= dynamic_cast< CMoldEltDefine
* >( pme
);
198 pitemes
= new CItemEltStruct( pl
);
199 pitemes
->BuildItem( pmed
);
202 void CItem::Load( const CStringEx
& _sxfilename
, const CStringEx _sxdate
)
206 void CItem::Save( const CStringEx
& _sxfilename
)
211 pitemes
->BuildForm( form
.GetBody(), vsxparents
);
212 pl
->SaveForm( form
, _sxfilename
);
215 CItemElt
* CItem::GetElt( const unsigned int _index
) const
218 return( pitemes
->GetElt( _index
) );
222 CItemElt
* CItem::GetElt( const CStringEx _sxname
) const
225 return( pitemes
->GetElt( _sxname
) );
229 void CItem::SetCurrentValue( const unsigned int _index
, const CStringEx s
)
231 CItemElt
* pie
= GetElt( _index
);
234 pie
->SetCurrentValue( s
);
235 pitemes
->SetModified( _index
);
238 uint
CItem::GetNbElt() const
241 return( pitemes
->GetNbElt() );
245 uint
CItem::GetNbParents() const
247 return (uint
)vsxparents
.size();
250 uint
CItem::GetNbElt( const unsigned int _index
) const
252 CItemElt
* pie
= GetElt( _index
);
255 return( pie
->GetNbElt() );
258 uint
CItem::GetInfos( const unsigned int _index
) const
260 CItemElt
* pie
= GetElt( _index
);
263 return( pie
->GetInfos() );
266 CStringEx
CItem::GetName( const unsigned int _index
) const
269 CItemElt
* pie
= GetElt( _index
);
275 return( pie
->GetName() );
278 CStringEx
CItem::GetCurrentResult( const unsigned int _index
) const
280 CItemElt
* pie
= GetElt( _index
);
286 return( pie
->GetCurrentResult() );
289 CStringEx
CItem::GetCurrentValue( const unsigned int _index
) const
291 CItemElt
* pie
= GetElt( _index
);
297 return( pie
->GetCurrentValue() );
306 CItemElt
* pie
= pitemes
->GetElt( i
++ );
309 CStringEx sxold
= pie
->GetCurrentValue();
310 pie
->SetParentValue( pie
->GetParentValue() );
311 pie
->SetCurrentValue( pie
->GetCurrentValue() );
312 b
|= ( sxold
!= pie
->GetCurrentValue() );
313 pie
= pitemes
->GetElt( i
++ );
318 CStringEx
CItem::GetFormula( const unsigned int _index
) const
320 CItemElt
* pie
= GetElt( _index
);
326 return( pie
->GetFormula() );
329 bool CItem::IsEnum( const unsigned int _index
) const
331 CItemElt
* pie
= GetElt( _index
);
334 return( ( pie
->GetInfos() & ITEM_ISENUM
) != 0 );
337 bool CItem::IsPredef( const unsigned int _index
) const
339 CItemElt
* pie
= GetElt( _index
);
342 CItemEltAtom
* piea
= dynamic_cast< CItemEltAtom
* >( pie
);
345 CMoldEltType
* pmet
= piea
->GetMoldType();
346 CStringEx sx
= pmet
->GetPredefDesignation( 0 );
347 return( !sx
.empty() );
350 bool CItem::CanEdit( const unsigned int _index
) const
352 CItemElt
* pie
= GetElt( _index
);
355 CItemEltAtom
* piea
= dynamic_cast< CItemEltAtom
* >( pie
);
358 return( !( pie
->GetInfos() & ITEM_ISENUM
) );
361 void CItem::GetListPredef( const unsigned int _index
, std::vector
< CStringEx
>& _vsx
) const
363 CItemElt
* pie
= GetElt( _index
);
366 CItemEltAtom
* piea
= dynamic_cast< CItemEltAtom
* >( pie
);
370 CMoldEltType
* pmet
= piea
->GetMoldType();
373 CStringEx sx
= pmet
->GetPredefDesignation( i
++ );
376 _vsx
.push_back( sx
);
377 sx
= pmet
->GetPredefDesignation( i
++ );
381 CStringEx
CItem::GetParent( const unsigned int _index
) const
383 if( _index
>= vsxparents
.size() )
388 return( vsxparents
[_index
].second
);
391 void CItem::SetParent( const unsigned int _index
, const CStringEx _sx
)
393 if( _index
>= vsxparents
.size() )
395 vsxparents
[_index
].second
= _sx
;
398 CStringEx
CItem::GetActivity( const unsigned int _index
) const
400 if( _index
>= vsxparents
.size() )
405 return( vsxparents
[_index
].first
);
408 void CItem::SetActivity( const unsigned int _index
, const CStringEx _sx
)
410 if( _index
>= vsxparents
.size() )
412 vsxparents
[_index
].first
= _sx
;
415 void CItem::AddList( const unsigned int _index
) const
417 CItemElt
* pie
= GetElt( _index
);
420 CItemEltList
* piel
= dynamic_cast< CItemEltList
* >( pie
);
426 void CItem::AddListChild( const unsigned int _index ) const
428 CItemElt* pie = GetElt( _index );
431 CItemElt* piep = pie->GetListParent();
434 CItemEltList* piel = dynamic_cast< CItemEltList* >( piep );
440 void CItem::DelListChild( const unsigned int _index
) const
442 CItemElt
* pie
= GetElt( _index
);
445 CItemElt
* piep
= pie
->GetListParent();
448 CItemEltList
* piel
= dynamic_cast< CItemEltList
* >( piep
);
454 void CItem::AddParent( const unsigned int _index
)
456 vsxparents
.push_back( std::make_pair( CStringEx("false"), CStringEx("filename.extension") ) );
459 void CItem::DelParent( const unsigned int _index
)
462 for( std::vector
< std::pair
< CStringEx
, CStringEx
> >::iterator it
= vsxparents
.begin(); it
!= vsxparents
.end(); ++it
)
465 vsxparents
.erase( it
);
470 void CItem::ClearParents ()