00001 #ifndef K3DSDK_HINTS_H 00002 #define K3DSDK_HINTS_H 00003 00004 // K-3D 00005 // Copyright (c) 1995-2008, Timothy M. Shead 00006 // 00007 // Contact: tshead@k-3d.com 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2 of the License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public 00020 // License along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00027 #include <k3dsdk/algebra.h> 00028 #include <k3dsdk/ihint.h> 00029 #include <k3dsdk/mesh.h> 00030 #include <k3dsdk/signal_system.h> 00031 00032 #include <boost/any.hpp> 00033 00034 #include <iosfwd> 00035 00036 namespace k3d 00037 { 00038 00040 namespace hint 00041 { 00042 00044 // slot_t 00045 00047 class print 00048 { 00049 public: 00050 print(ihint* Hint); 00051 00052 ihint* const hint; 00053 }; 00054 00056 std::ostream& operator<<(std::ostream& Stream, const print& RHS); 00057 00059 // slot_t 00060 00062 typedef sigc::slot<void, ihint*> slot_t; 00063 00065 // bitmap_dimensions_changed 00066 00068 class bitmap_dimensions_changed : 00069 public ihint 00070 { 00071 public: 00072 ihint* clone(); 00073 void print(std::ostream& Stream); 00074 00075 static bitmap_dimensions_changed* instance(); 00076 }; 00077 00079 // bitmap_pixels_changed 00080 00082 class bitmap_pixels_changed : 00083 public ihint 00084 { 00085 public: 00086 ihint* clone(); 00087 void print(std::ostream& Stream); 00088 00089 static bitmap_pixels_changed* instance(); 00090 }; 00091 00093 // selection_changed 00094 00096 class selection_changed : 00097 public ihint 00098 { 00099 public: 00100 ihint* clone(); 00101 void print(std::ostream& Stream); 00102 00103 static selection_changed* instance(); 00104 }; 00105 00107 // mesh_geometry_changed 00108 00110 class mesh_geometry_changed : 00111 public ihint 00112 { 00113 public: 00114 ihint* clone(); 00115 void print(std::ostream& Stream); 00116 00117 static mesh_geometry_changed* instance(); 00118 00120 k3d::mesh::indices_t changed_points; 00122 k3d::matrix4 transformation_matrix; 00123 }; 00124 00126 // mesh_topology_changed 00127 00129 class mesh_topology_changed : 00130 public ihint 00131 { 00132 public: 00133 ihint* clone(); 00134 void print(std::ostream& Stream); 00135 00136 static mesh_topology_changed* instance(); 00137 }; 00138 00140 // mesh_deleted 00141 00143 class mesh_deleted : 00144 public ihint 00145 { 00146 public: 00147 ihint* clone(); 00148 void print(std::ostream& Stream); 00149 00150 static mesh_deleted* instance(); 00151 }; 00152 00154 // file_changed 00155 00157 class file_changed : 00158 public ihint 00159 { 00160 public: 00161 ihint* clone(); 00162 void print(std::ostream& Stream); 00163 00164 static file_changed* instance(); 00165 }; 00166 00168 // graph_topology_changed 00169 00171 class graph_topology_changed : 00172 public ihint 00173 { 00174 public: 00175 ihint* clone(); 00176 void print(std::ostream& Stream); 00177 00178 static graph_topology_changed* instance(); 00179 }; 00180 00182 // graph_attributes_changed 00183 00185 class graph_attributes_changed : 00186 public ihint 00187 { 00188 public: 00189 ihint* clone(); 00190 void print(std::ostream& Stream); 00191 00192 static graph_attributes_changed* instance(); 00193 }; 00194 00196 // any 00197 00199 class any 00200 { 00201 public: 00202 }; 00203 00205 // none 00206 00208 class none 00209 { 00210 public: 00211 }; 00212 00214 // unchanged 00215 00217 class unchanged 00218 { 00219 public: 00220 }; 00221 00223 // hint_traits 00224 00226 template<typename HintT> 00227 class hint_traits 00228 { 00229 public: 00230 }; 00231 00232 template<> 00233 class hint_traits<bitmap_dimensions_changed> 00234 { 00235 public: 00236 static bool_t match(ihint* Hint) 00237 { 00238 return dynamic_cast<bitmap_dimensions_changed*>(Hint); 00239 } 00240 00241 static ihint* convert(ihint*) 00242 { 00243 static bitmap_dimensions_changed hint; 00244 return &hint; 00245 } 00246 }; 00247 00248 template<> 00249 class hint_traits<bitmap_pixels_changed> 00250 { 00251 public: 00252 static bool_t match(ihint* Hint) 00253 { 00254 return dynamic_cast<bitmap_pixels_changed*>(Hint); 00255 } 00256 00257 static ihint* convert(ihint*) 00258 { 00259 static bitmap_pixels_changed hint; 00260 return &hint; 00261 } 00262 }; 00263 00264 template<> 00265 class hint_traits<selection_changed> 00266 { 00267 public: 00268 static bool_t match(ihint* Hint) 00269 { 00270 return dynamic_cast<selection_changed*>(Hint); 00271 } 00272 00273 static ihint* convert(ihint*) 00274 { 00275 static selection_changed hint; 00276 return &hint; 00277 } 00278 }; 00279 00280 template<> 00281 class hint_traits<mesh_topology_changed> 00282 { 00283 public: 00284 static bool_t match(ihint* Hint) 00285 { 00286 return dynamic_cast<mesh_topology_changed*>(Hint); 00287 } 00288 00289 static ihint* convert(ihint*) 00290 { 00291 static mesh_topology_changed hint; 00292 return &hint; 00293 } 00294 }; 00295 00296 template<> 00297 class hint_traits<mesh_geometry_changed> 00298 { 00299 public: 00300 static bool_t match(ihint* Hint) 00301 { 00302 return dynamic_cast<mesh_geometry_changed*>(Hint); 00303 } 00304 00305 static ihint* convert(ihint*) 00306 { 00307 static mesh_geometry_changed hint; 00308 return &hint; 00309 } 00310 }; 00311 00312 template<> 00313 class hint_traits<graph_topology_changed> 00314 { 00315 public: 00316 static bool_t match(ihint* Hint) 00317 { 00318 return dynamic_cast<graph_topology_changed*>(Hint); 00319 } 00320 00321 static ihint* convert(ihint*) 00322 { 00323 static graph_topology_changed hint; 00324 return &hint; 00325 } 00326 }; 00327 00328 template<> 00329 class hint_traits<graph_attributes_changed> 00330 { 00331 public: 00332 static bool_t match(ihint* Hint) 00333 { 00334 return dynamic_cast<graph_attributes_changed*>(Hint); 00335 } 00336 00337 static ihint* convert(ihint*) 00338 { 00339 static graph_attributes_changed hint; 00340 return &hint; 00341 } 00342 }; 00343 00344 template<> 00345 class hint_traits<any> 00346 { 00347 public: 00348 static bool_t match(ihint*) 00349 { 00350 return true; 00351 } 00352 }; 00353 00354 template<> 00355 class hint_traits<none> 00356 { 00357 public: 00358 static bool_t match(ihint*) 00359 { 00360 return false; 00361 } 00362 00363 static ihint* convert(ihint*) 00364 { 00365 return 0; 00366 } 00367 }; 00368 00369 template<> 00370 class hint_traits<unchanged> 00371 { 00372 public: 00373 static ihint* convert(ihint* Hint) 00374 { 00375 return Hint; 00376 } 00377 }; 00378 00380 // last_conversion 00381 00382 class last_conversion 00383 { 00384 }; 00385 00387 // convert 00388 00389 template<typename SourceT, typename TargetT, typename NextT = last_conversion> 00390 struct convert 00391 { 00392 typedef SourceT Source; 00393 typedef TargetT Target; 00394 typedef NextT Next; 00395 }; 00396 00397 namespace detail 00398 { 00399 00400 template<typename ListT> 00401 void execute(ihint* const Hint, const slot_t& Slot) 00402 { 00403 if(hint_traits<typename ListT::Source>::match(Hint)) 00404 { 00405 Slot(hint_traits<typename ListT::Target>::convert(Hint)); 00406 } 00407 else 00408 { 00409 execute<typename ListT::Next>(Hint, Slot); 00410 } 00411 } 00412 00413 template<> 00414 inline void execute<last_conversion>(ihint* const Hint, const slot_t&) 00415 { 00416 std::cerr << "unhandled hint: " << print(Hint) << std::endl; 00417 } 00418 00419 template<typename ListT> 00420 class converter 00421 { 00422 public: 00423 converter(const slot_t& Slot) : 00424 slot(Slot) 00425 { 00426 } 00427 00428 void operator()(ihint* const Hint) 00429 { 00430 execute<ListT>(Hint, slot); 00431 } 00432 00433 private: 00434 slot_t slot; 00435 }; 00436 00437 } // namespace detail 00438 00440 // converter 00441 00445 template<typename ListT> 00446 detail::converter<ListT> converter(const sigc::slot<void, ihint*>& Slot) 00447 { 00448 return detail::converter<ListT>(Slot); 00449 } 00450 00451 } // namespace hint 00452 00453 } // namespace k3d 00454 00455 #endif // !K3DSDK_HINTS_H 00456
1.6.3