cgma
|
00001 //------------------------------------------------------------------------ 00002 // Class GeomDataObserver 00003 // Description: Observer class that stores/caches specific geometric 00004 // information (for example, the area for a surface. 00005 // 00006 // Author: David White 00007 // Creation Date: 9/7/2003 00008 //------------------------------------------------------------------------ 00009 #include "GeomDataObserver.hpp" 00010 #include "RefEntity.hpp" 00011 #include "GeometryEvent.hpp" 00012 00013 GeomDataObserver::GeomDataObserver(RefEntity* watched) 00014 : myRefEntity(watched) 00015 { 00016 measureSet = CUBIT_FALSE; 00017 //initialize to something weird. 00018 myMeasure = -CUBIT_DBL_MAX; 00019 } 00020 00021 GeomDataObserver::~GeomDataObserver() 00022 { 00023 unregister_observable( myRefEntity ); 00024 } 00025 00026 GeomDataObserver* GeomDataObserver::get( RefEntity* on_this ) 00027 { 00028 DLIList<CubitObserver*> list; 00029 GeomDataObserver* eo = NULL; 00030 00031 on_this->get_observer_list(list); 00032 for (int i = list.size(); i--; ) 00033 { 00034 if ( (eo = dynamic_cast<GeomDataObserver*>(list.step_and_get()) )) 00035 break; 00036 } 00037 return eo; 00038 } 00039 00040 GeomDataObserver* GeomDataObserver::create( RefEntity* on_this ) { 00041 GeomDataObserver* eo = get(on_this); 00042 if (eo) 00043 return eo; 00044 00045 eo = new GeomDataObserver(on_this); 00046 eo->register_observable(on_this); 00047 return eo; 00048 } 00049 00050 void GeomDataObserver::notify_observer(const CubitEvent* event) 00051 { 00052 const GeometryEvent* geom_event = dynamic_cast<const GeometryEvent*>(event); 00053 00054 if(geom_event) 00055 { 00056 assert(geom_event->get_entity() == myRefEntity); 00057 00058 switch (geom_event->get_type()) 00059 { 00060 case GeometryEvent::GEOMETRY_TOPOLOGY_MODIFIED: 00061 case GeometryEvent::TOPOLOGY_MODIFIED: 00062 case GeometryEvent::GEOMETRY_MODIFIED: 00063 case GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED: 00064 break; 00065 default: 00066 return; 00067 } 00068 00069 /* don't call virtual functions or access 00070 class data after this! */ 00071 delete this; 00072 } 00073 } 00074