1 #include <cpPlugins/Interface/Workspace.h>
2 #include <third_party/tinyxml/tinyxml.h>
4 // -------------------------------------------------------------------------
5 std::string cpPlugins::Interface::Workspace::
6 LoadWorkspace( const std::string& fname )
8 TiXmlDocument* doc = new TiXmlDocument( fname.c_str( ) );
10 TiXmlElement* root = doc->RootElement( );
11 if( std::string( root->Value( ) ) != "cpPlugins_Workspace" )
12 return( "cpPlugins::Interface::Workspace: No valid workspace" );
13 std::stringstream err;
16 TiXmlElement* plugins = root->FirstChildElement( "plugins" );
17 while( plugins != NULL )
19 const char* value = plugins->Attribute( "filename" );
22 if( !( this->LoadPlugins( value ) ) )
23 err << "no valid plugins file \"" << value << "\"" << std::endl;
26 plugins = plugins->NextSiblingElement( "plugins" );
31 plugins = root->FirstChildElement( "plugins_dir" );
32 while( plugins != NULL )
34 const char* value = plugins->Attribute( "path" );
38 if( plugins->QueryIntAttribute( "recursive", &recursive ) != TIXML_SUCCESS )
40 if( !( this->LoadPluginsPath( value, recursive == 1 ) ) )
41 err << "No valid plugins path \"" << value << "\"" << std::endl;
44 plugins = plugins->NextSiblingElement( "plugins_dir" );
49 TiXmlElement* filter = root->FirstChildElement( "filter" );
50 while( filter != NULL )
52 const char* class_value = filter->Attribute( "class" );
53 const char* name_value = filter->Attribute( "name" );
54 if( class_value != NULL && name_value != NULL )
56 if( this->CreateFilter( class_value, name_value ) )
59 TParameters* parameters = this->GetParameters( name_value );
60 TiXmlElement* param = filter->FirstChildElement( "parameter" );
61 while( param != NULL )
63 const char* param_name = param->Attribute( "name" );
64 const char* param_type = param->Attribute( "type" );
65 if( param_name != NULL && param_type != NULL )
67 std::string param_type_str( param_type );
68 const char* value = param->Attribute( "value" );
71 std::istringstream value_str( value );
72 if( param_type_str == "String" )
73 parameters->SetString( param_name, value );
74 else if( param_type_str == "Bool" )
75 parameters->SetBool( param_name, value[ 0 ] != '0' );
76 else if( param_type_str == "Int" )
80 parameters->SetInt( param_name, v );
82 else if( param_type_str == "Uint" )
86 parameters->SetUint( param_name, v );
88 else if( param_type_str == "Real" )
92 parameters->SetReal( param_name, v );
95 else if( param_type_str == "Index" )
96 else if( param_type_str == "Point" )
97 else if( param_type_str == "Vector" )
102 if( param_type_str == "StringList" )
104 TiXmlElement* item = param->FirstChildElement( "item" );
105 while( item != NULL )
107 value = item->Attribute( "value" );
109 parameters->AddToStringList( param_name, value );
110 item = item->NextSiblingElement( "item" );
114 else if( param_type_str == "BoolList" )
116 TiXmlElement* item = param->FirstChildElement( "item" );
117 while( item != NULL )
119 value = item->Attribute( "value" );
121 parameters->AddToBoolList( param_name, value[ 0 ] != '0' );
122 item = item->NextSiblingElement( "item" );
126 else if( param_type_str == "IntList" )
128 TiXmlElement* item = param->FirstChildElement( "item" );
129 while( item != NULL )
131 value = item->Attribute( "value" );
134 std::istringstream value_str( value );
137 parameters->AddToIntList( param_name, v );
140 item = item->NextSiblingElement( "item" );
144 else if( param_type_str == "UintList" )
146 TiXmlElement* item = param->FirstChildElement( "item" );
147 while( item != NULL )
149 value = item->Attribute( "value" );
152 std::istringstream value_str( value );
153 TParameters::TUint v;
155 parameters->AddToUintList( param_name, v );
158 item = item->NextSiblingElement( "item" );
162 else if( param_type_str == "RealList" )
164 TiXmlElement* item = param->FirstChildElement( "item" );
165 while( item != NULL )
167 value = item->Attribute( "value" );
170 std::istringstream value_str( value );
171 TParameters::TReal v;
173 parameters->AddToRealList( param_name, v );
176 item = item->NextSiblingElement( "item" );
181 else if( param_type_str == "IndexList" )
182 else if( param_type_str == "PointList" )
183 else if( param_type_str == "VectorList" )
184 else if( param_type_str == "Choices" );
189 param = param->NextSiblingElement( "parameter" );
195 << "No valid class \"" << class_value << "\" with name \""
196 << name_value << "\"" << std::endl;
199 err << "Incomplete data." << std::endl;
200 filter = filter->NextSiblingElement( "filter" );
205 TiXmlElement* connection = root->FirstChildElement( "connection" );
206 while( connection != NULL )
208 TiXmlElement* orig = connection->FirstChildElement( "origin" );
209 TiXmlElement* dest = connection->FirstChildElement( "destination" );
210 if( orig != NULL && dest != NULL )
212 const char* orig_filter = orig->Attribute( "filter" );
213 const char* dest_filter = dest->Attribute( "filter" );
214 const char* orig_name = orig->Attribute( "name" );
215 const char* dest_name = dest->Attribute( "name" );
217 orig_filter != NULL && dest_filter != NULL &&
218 orig_name != NULL && dest_name != NULL
220 this->Connect( orig_filter, dest_filter, orig_name, dest_name );
223 connection = connection->NextSiblingElement( "connection" );
229 return( err.str( ) );
232 // -------------------------------------------------------------------------
233 std::string cpPlugins::Interface::Workspace::
234 SaveWorkspace( const std::string& fname ) const