This is BBMoleculeShape.m in view mode; [Download] [Up]
/* BBMoleculeShape.m * * This object is the world of a molecule. It maintains a list of regions that * have to be drawn to paint the molecule. We use the molecules visibleRegions * and recommend certain methods to be available for every shape-provider. * * For more interface-info see the header file. More in depth information * can be found in the source-code. * * Written by: Thomas Engel * Created: 22.12.1993 (Copyleft) * Last modified: 17.05.1994 */ #import "BBMoleculeShape.h" #import "BBMolecule.h" #import "BBRegionShape.h" @implementation BBMoleculeShape - initFrom:someRegions asPartOf:aMolecule; { self = [super init]; if( !self ) return self; // OK. We really are an object...here we go with our init. ourRegions = [someRegions copy]; ourMolecule = aMolecule; shapeList = [List new]; [self update]; return self; } - free { [ourRegions free]; [shapeList free]; return [super free]; } - renderSelf:(RtToken)context { // We won't do anything here. We are only a collector of subshapes. // In this case they are regions. return self; } - update { // With this method we will create a shapeList for the current molecule // and forget about the old one. id aShape; int i; descendant = nil; [shapeList freeObjects]; for( i=0; i<[ourRegions count]; i++ ) { // Now we will ask every visible group for its shape. // The shapeList will keep track of every object. // We have the right to free those objects! aShape = [[ourRegions objectAt:i] shape]; [aShape group:self]; [shapeList addObject:aShape]; } return self; } - rotationStyleOn:(BOOL)aFlag { // Here we will take every shape from the shapeList. Tell it to use // the regions draw/or rotation style and cause it to rearange its shapes. // No redraw is triggered! int i; id aShape; id aRegion; for( i=0; i<[shapeList count]; i++ ) { aShape = [shapeList objectAt:i]; aRegion = [aShape region]; if( aFlag == YES ) [aShape setRenderingStyle:[aRegion rotationStyle]]; else [aShape setRenderingStyle:[aRegion drawingStyle]]; } // [aShape update]; << I should check that !! return self; } - molecule { return ourMolecule; } - addRegion:aRegion { if( [ourRegions indexOf:aRegion] == NX_NOT_IN_LIST ) { [ourRegions addObject:aRegion]; [self update]; } return self; } @end /* * History: 17.05.95 Added the molecule reference. * * 07.05.94 Changed the naming to BB... * * 15.01.94 Changed the MolShape to ask the molecule for ist * visibleGroups and ask those visibleGroups for their * shapes. * * 25.12.93 Changed clas to include atomShapes/bondShapes. * * 22.12.93 First running version..display a simple molecule. * * * Notes: - shapeList. Maybe it is really useless because I am able to get all * the shapes later too through the descendent etc methods of a 3D * shape. But I will leave it for the moment because it serves the * purpose of esaily freeing all subshapes. So not that useless * (10.3.94) * * - I should make it a BBRegionShape subclass soon..or ?. * * * Bugs: - Using the update while adding another region might be somewhat * stupid but right now its easy and it works. */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.