This is BBBasicAtom.m in view mode; [Download] [Up]
/* BBBasicAtom.m * * This is a basic atom. It has the minmum information a atom should provide. * This class is used to build the atomlibrary. * * For interface-info see the header file. The comments in this file mostly * cover only the real implementation details. * * Written by: Thomas Engel * Created: 09.01.1994 (Copyleft) * Last modified: 07.11.1994 */ #import "BBBasicAtom.h" #import <misckit/MiscString.h> @implementation BBBasicAtom - init { self = [super init]; if( !self ) return self; // OK. We really are an object...here we go with our init. // Lets set the icon and get the string objects. // By default we do not have a private color, or proton or what ever. // So lets to the impossible-value setting. The string objects are // created and freed as needed. [self setImage:[NXImage findImageNamed:"BasicAtomIcon"]]; [self setLeaf:YES]; hasPrivatName = NO; neutrons = -1; protons = -1; mass = -1; radius = -1; vanDerWaals = -1; hasPrivateColor = NO; return self; } - free { // We do not free the motherAtom and icon because we did not create them // an they might be used somewhere else. [symbol free]; [symbolExtention free]; [infoText free]; return [super free]; } - setMotherAtom:anAtom { motherAtom = anAtom; return self; } - motherAtom { return motherAtom; } - setName:(const char *)aString { // By the time we set or name we should check if we have a nameObject or // if we should free it because somebody wants to set the empyt string. [super setName:aString]; if( strlen( aString ) == 0 ) hasPrivatName = NO; else hasPrivatName = YES; return self; } - (const char *)name { if( hasPrivatName ) return [super name]; else return [motherAtom name]; } - setSymbol:(const char *)aString { // By the time we set or symbol we should check if we have a symbolObject // or if we should free it because somebody wants to set an empty string. if( !symbol ) { symbol = [MiscString new]; [symbol setStringValue:aString]; } else if( !aString ) { [symbol free]; symbol = nil; } return self; } - (const char *)symbol { if( symbol ) return [symbol stringValue]; else return [motherAtom symbol]; } - symbolObject { if( symbol ) return symbol; else return [motherAtom symbolObject]; } - setSymbolExtention:(const char *)aString { // By the time we set or symbol we should check if we have a symbolObject // or if we should free it because somebody wants to set an empty string. if( !symbolExtention ) { symbolExtention = [MiscString new]; [symbolExtention setStringValue:aString]; } else if( !aString ) { [symbolExtention free]; symbolExtention = nil; } return self; } - (const char *)symbolExtention { if( symbolExtention ) return [symbolExtention stringValue]; else return [motherAtom symbolExtention]; } - symbolExtentionObject { if( symbolExtention ) return symbolExtention; else return [motherAtom symbolExtentionObject]; } - setProtons:(short)anInt { protons = anInt; return self; } - (short)protons { if( protons != -1 ) return protons; else return [motherAtom protons]; } - setNeutrons:(short)anInt { neutrons = anInt; return self; } - (short)neutrons { if( neutrons != -1 ) return neutrons; else return [motherAtom neutrons]; } - setMass:(float)aFloat { mass = aFloat; return self; } - (float)mass { if( mass != -1 ) return mass; else return [motherAtom mass]; } - setRadius:(float)aFloat { // Here we set the radius. If vanDerWaals has not be set we make a guess // by *2. So we can have those nice spacefilling pictures. radius = aFloat; if( vanDerWaals == -1 ) vanDerWaals = aFloat * 2; return self; } - (float)radius { if( radius != -1 ) return radius; else return [motherAtom radius]; } - setVanDerWaalsRadius:(float)aFloat { vanDerWaals = aFloat; return self; } - (float)vanDerWaalsRadius { if( vanDerWaals != -1 ) return vanDerWaals; else return [motherAtom vanDerWaalsRadius]; } - setColor:(NXColor)aColor { hasPrivateColor = YES; color = aColor; return self; } - (NXColor)color { if( hasPrivateColor ) return color; else return [motherAtom color]; } @end /* * History: 07.11.94 Changed the Naming and symboling stuff to support * extended symbols. * * 30.10.94 Switched to useing the MiscString. * * 02.05.94 Are are draggable and the BBBasicAtom now. * * 15.01.94 Added the automatic vanDerWaals setting to -radius. * * 12.01.94 Added the mass and vanDerWaals Radius. * * 10.01.94 Changed some methods to work properly with our * new objectWell. * * 09.01.94 First created this object. Maybe we will make the normal * Atom a subclass of this object. * * If we are asked to set a value we should always check wether our mother has * it already or not!!!! * * Bugs: - Might be useful..and bug free. */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.