00001 /*===========================================================================*\ 00002 * * 00003 * OpenFlipper * 00004 * Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen * 00005 * www.openflipper.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenFlipper. * 00009 * * 00010 * OpenFlipper is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenFlipper is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenFlipper. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 6727 $ * 00038 * $Author: moebius $ * 00039 * $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $ * 00040 * * 00041 \*===========================================================================*/ 00042 00043 00044 00045 00046 //============================================================================= 00047 // 00048 // Plugin Functions 00049 // 00050 //============================================================================= 00051 00052 #include <OpenFlipper/common/Types.hh> 00053 00054 #include "PluginFunctions.hh" 00055 00056 namespace PluginFunctions { 00057 00058 00059 ObjectIterator::ObjectIterator( IteratorRestriction _restriction , DataType _dataType) { 00060 00061 // Initialize with invalid pos 00062 pos_ = 0; 00063 00064 // Store the restriction for the operator ( Source/Target ) 00065 restriction_ = _restriction; 00066 00067 // Store the requested DataType 00068 dataType_ = _dataType; 00069 00070 // Start at the root Node 00071 BaseObject* currentPos = objectRoot(); 00072 00073 // Take the first element which is an baseObjectData 00074 proceedToNextBaseObjectData(currentPos); 00075 00076 while ( (currentPos != objectRoot()) ) { 00077 00078 // Return only target objects if requested 00079 if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) { 00080 proceedToNextBaseObjectData(currentPos); 00081 continue; 00082 } 00083 00084 // Return only source objects if requested 00085 if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) { 00086 proceedToNextBaseObjectData(currentPos); 00087 continue; 00088 } 00089 00090 // Return only the right dataType 00091 if ( _dataType != DATA_ALL ) 00092 if ( ! (currentPos->dataType( dataType_ ) ) ) { 00093 proceedToNextBaseObjectData(currentPos); 00094 continue; 00095 } 00096 00097 // found a valid object 00098 pos_ = dynamic_cast<BaseObjectData* > (currentPos); 00099 break; 00100 } 00101 } 00102 00103 ObjectIterator::ObjectIterator(BaseObjectData* pos, IteratorRestriction _restriction , DataType _data) 00104 { 00105 restriction_ = _restriction; 00106 pos_ = pos; 00107 dataType_ = _data; 00108 }; 00109 00110 00111 bool ObjectIterator::operator==( const ObjectIterator& _rhs) { 00112 return ( _rhs.pos_ == pos_ ); 00113 } 00114 00115 bool ObjectIterator::operator!=( const ObjectIterator& _rhs) { 00116 return ( _rhs.pos_ != pos_ ); 00117 } 00118 00119 ObjectIterator& ObjectIterator::operator=( const ObjectIterator& _rhs) { 00120 pos_ = _rhs.pos_; 00121 return *this; 00122 } 00123 00124 00125 ObjectIterator::pointer ObjectIterator::operator->(){ 00126 return pos_; 00127 } 00128 00129 ObjectIterator& ObjectIterator::operator++() { 00130 00131 // Convert our pointer to the basic one 00132 BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_); 00133 00134 // Get the next objectData element in the tree 00135 proceedToNextBaseObjectData(currentPos); 00136 00137 while ( (currentPos != objectRoot() ) ) { 00138 00139 // Return only target objects if requested 00140 if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) { 00141 proceedToNextBaseObjectData(currentPos); 00142 continue; 00143 } 00144 00145 // Return only source objects if requested 00146 if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) { 00147 proceedToNextBaseObjectData(currentPos); 00148 continue; 00149 } 00150 00151 // Return only the right dataType 00152 if ( ! (currentPos->dataType( dataType_ ) ) ) { 00153 proceedToNextBaseObjectData(currentPos); 00154 continue; 00155 } 00156 00157 // found a valid object 00158 pos_ = dynamic_cast<BaseObjectData* > (currentPos); 00159 return *this; 00160 } 00161 00162 // No valid object found 00163 pos_ = 0; 00164 return *this; 00165 } 00166 00167 ObjectIterator& ObjectIterator::operator--() { 00168 std::cerr << "TODO :--" << std::endl; 00169 return *this; 00170 } 00171 00177 BaseObjectData* ObjectIterator::operator*() { 00178 return pos_; 00179 } 00180 00182 ObjectIterator objectsEnd() { 00183 return ObjectIterator(0); 00184 } 00185 00186 void ObjectIterator::proceedToNextBaseObjectData(BaseObject*& _object) { 00187 00188 _object = _object->next(); 00189 00190 // Go through the tree and stop at the root node or if we found a baseObjectData Object 00191 while ( (_object != objectRoot()) && !dynamic_cast<BaseObjectData* > (_object) ) 00192 _object = _object->next(); 00193 } 00194 00195 00196 00197 }