Changeset 8206 for code/branches/dockingsystem2/src/modules/objects/triggers/DistanceMultiTrigger.cc
- Timestamp:
- Apr 7, 2011, 10:19:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/dockingsystem2/src/modules/objects/triggers/DistanceMultiTrigger.cc
r8079 r8206 43 43 { 44 44 45 /*static*/ const std::string DistanceMultiTrigger::beaconModeOff_s = "off"; 46 /*static*/ const std::string DistanceMultiTrigger::beaconModeIdentify_s = "identify"; 47 /*static*/ const std::string DistanceMultiTrigger::beaconModeExlcude_s = "exclude"; 48 45 49 CreateFactory(DistanceMultiTrigger); 46 50 … … 49 53 Default Constructor. Registers the object and initializes default values. 50 54 */ 51 DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator) 55 DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator), beaconMask_(NULL) 52 56 { 53 57 RegisterObject(DistanceMultiTrigger); 54 58 55 59 this->distance_ = 100.0f; 60 this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::off); 56 61 this->targetName_ = ""; 57 this->singleTargetMode_ = false;58 62 } 59 63 … … 64 68 DistanceMultiTrigger::~DistanceMultiTrigger() 65 69 { 66 70 if(this->beaconMask_ != NULL) 71 delete this->beaconMask_; 67 72 } 68 73 … … 76 81 77 82 XMLPortParam(DistanceMultiTrigger, "distance", setDistance, getDistance, xmlelement, mode); 83 XMLPortParam(DistanceMultiTrigger, "beaconMode", setBeaconMode, getBeaconMode, xmlelement, mode); 78 84 XMLPortParam(DistanceMultiTrigger, "targetname", setTargetName, getTargetName, xmlelement, mode); 79 85 } … … 126 132 127 133 // Check for new objects that are in range 128 for(ClassTreeMaskObjectIterator it = this->getTargetMask().begin(); it != this->getTargetMask().end(); ++it) 134 ClassTreeMask targetMask = this->getTargetMask(); 135 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify) 136 targetMask = *this->beaconMask_; 137 138 for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it) 129 139 { 130 140 WorldEntity* entity = static_cast<WorldEntity*>(*it); 131 141 132 // If the DistanceMultiTrigger is in single-target mode. 133 if(this->singleTargetMode_) 134 { 135 // If the object that is a target is no DistanceTriggerBeacon, then the DistanceMultiTrigger can't be in single-target mode. 136 if(!entity->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier())) 142 // If the DistanceMultiTrigger is in identify mode and the DistanceTriggerBeacon attached to the object has the wrong name we ignore it. 143 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify) 144 { 145 if(entity->getName() != this->targetName_) 146 continue; 147 // If the object, the DistanceTriggerBeacon is attached to, is not a target of this DistanceMultiTrigger. 148 else if(this->getTargetMask().isExcluded(entity->getParent()->getIdentifier())) 149 continue; 150 } 151 152 // If the DistanceMultiTrigger is in exclude mode and the DistanceTriggerBeacon attached to the object has the right name, we ignore it. 153 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::exclude) 154 { 155 156 const std::set<WorldEntity*> attached = entity->getAttachedObjects(); 157 bool found = false; 158 for(std::set<WorldEntity*>::const_iterator it = attached.begin(); it != attached.end(); it++) 137 159 { 138 this->singleTargetMode_ = false; 139 COUT(2) << "DistanceMultiTrigger " << this->getName() << " (&" << this << ")" << "is in single-target mode but the target is '" << entity->getIdentifier()->getName() << "' instead of DistanceTriggerBeacon. Setting single-target mode to false." << std::endl; 160 if((*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(*it)->getName() == this->targetName_) 161 { 162 found = true; 163 break; 164 } 140 165 } 141 // If the target name and the name of the DistancTriggerBeacon don't match. 142 else if(entity->getName().compare(this->targetName_) != 0) 166 if(found) 143 167 continue; 144 168 } … … 153 177 continue; 154 178 155 // Change the entity to the parent of the DistanceTriggerBeacon (if in single-target-mode), which is the entity to which the beacon is attached.156 if(this-> singleTargetMode_)179 // Change the entity to the parent of the DistanceTriggerBeacon (if in identify-mode), which is the entity to which the beacon is attached. 180 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify) 157 181 entity = entity->getParent(); 158 182 … … 171 195 return queue; 172 196 } 173 174 /** 175 @brief 176 Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger. 177 @param targetname 178 The name of the DistanceTriggerBeacon as a string. 179 */ 180 void DistanceMultiTrigger::setTargetName(const std::string& targetname) 181 { 182 // If the targetname is no blank string single-target mode is enabled. 183 if(targetname != "") 184 this->singleTargetMode_ = true; 197 198 /** 199 @brief 200 Set the beacon mode. 201 @param mode 202 The mode as an enum. 203 */ 204 void DistanceMultiTrigger::setBeaconModeDirect(distanceMultiTriggerBeaconMode::Value mode) 205 { 206 this->beaconMode_ = mode; 207 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify && this->beaconMask_ == NULL) 208 { 209 this->beaconMask_ = new ClassTreeMask(); 210 this->beaconMask_->exclude(Class(BaseObject)); 211 this->beaconMask_->include(Class(DistanceTriggerBeacon)); 212 } 213 } 214 215 /** 216 @brief 217 Get the beacon mode. 218 @return 219 Returns the mode as a string. 220 */ 221 const std::string& DistanceMultiTrigger::getBeaconMode(void) const 222 { 223 switch(this->getBeaconModeDirect()) 224 { 225 case distanceMultiTriggerBeaconMode::off : 226 return DistanceMultiTrigger::beaconModeOff_s; 227 case distanceMultiTriggerBeaconMode::identify: 228 return DistanceMultiTrigger::beaconModeIdentify_s; 229 case distanceMultiTriggerBeaconMode::exclude: 230 return DistanceMultiTrigger::beaconModeExlcude_s; 231 default : 232 assert(0); // This is impossible. 233 return BLANKSTRING; 234 } 235 } 236 237 /** 238 @brief 239 Set the beacon mode. 240 @param mode 241 The mode as a string. 242 */ 243 void DistanceMultiTrigger::setBeaconMode(const std::string& mode) 244 { 245 if(mode == DistanceMultiTrigger::beaconModeOff_s) 246 this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::off); 247 else if(mode == DistanceMultiTrigger::beaconModeIdentify_s) 248 this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::identify); 249 else if(mode == DistanceMultiTrigger::beaconModeExlcude_s) 250 this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::exclude); 185 251 else 186 this->singleTargetMode_ = false; 187 188 this->targetName_ = targetname; 252 COUT(1) << "Invalid beacon mode in DistanceMultiTrigger." << endl; 189 253 } 190 254
Note: See TracChangeset
for help on using the changeset viewer.