| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

KeyedType.h

Go to the documentation of this file.
00001 #ifndef OnXSvc_KeyedType_h
00002 #define OnXSvc_KeyedType_h
00003 
00004 // Inheritance :
00005 #include <Lib/Interfaces/IIterator.h>
00006 #include <OnX/Core/BaseType.h>
00007 
00008 class IDataProviderSvc;
00009 
00010 #include <OnXSvc/ISoConversionSvc.h>
00011 #include <OnXSvc/IUserInterfaceSvc.h>
00012 
00013 #include <Lib/Interfaces/ISession.h>
00014 #include <Lib/Out.h>
00015 #include <Lib/smanip.h>
00016 
00017 #include <GaudiKernel/IDataProviderSvc.h>
00018 #include <GaudiKernel/SmartDataPtr.h>
00019 #include <GaudiKernel/System.h>
00020 #include <GaudiKernel/KeyedContainer.h>
00021 
00022 namespace OnXSvc {
00023 
00024 template <class Object> 
00025 class KeyedIterator : public Lib::IIterator {
00026  public: //Lib::IIterator
00027   virtual Lib::Identifier object() {
00028     if(!fVector) return 0;
00029     if(fIterator==fVector->end()) return 0;
00030     return *fIterator;
00031   }
00032   virtual void next() { 
00033     if(!fVector) return;
00034     // Skip null objects.
00035     while(true) {
00036       ++fIterator;        
00037       if(fIterator==fVector->end()) return;
00038       if(*fIterator) return;
00039     }
00040   }
00041   virtual void* tag() { return 0;}
00042 public:
00043   typedef KeyedContainer< Object, Containers::HashMap> Collection;
00044   KeyedIterator(Collection* aVector = 0):fVector(aVector) {
00045     if(fVector) fIterator = fVector->begin();
00046   }
00047 private:
00048   Collection* fVector;
00049   typename Collection::iterator fIterator;
00050 };
00051 
00052 template <class Object> 
00053 class KeyedType : public OnX::BaseType {
00054 private:
00055   typedef KeyedContainer< Object, Containers::HashMap> Collection;
00056 public: //Lib::IType
00057   virtual void* cast(const std::string& aClass) const {
00058     //FIXME : needed with g++-3.23 so that 
00059     //        the virtuality over the safe cast works !
00060     if(aClass=="Slash::Data::IVisualizer") {
00061       return (void*)static_cast<const Slash::Data::IVisualizer*>(this);
00062     } else {
00063       return OnX::BaseType::cast(aClass);
00064     }
00065   }
00066   virtual std::string name() const {  return fType;}
00067   virtual Lib::IIterator* iterator() {
00068     if(fIterator) return fIterator;
00069     if(!fDataProviderSvc) {
00070       Lib::Out out(printer());
00071       out << "OnXSvc::KeyedType<>::iterator :"
00072           << " no data provider found."
00073           << Lib::endl;
00074       return new KeyedIterator< Object >();
00075     }
00076     SmartDataPtr<DataObject> smartDataObject(fDataProviderSvc,fLocation);
00077     if(smartDataObject) {}
00078     DataObject* dataObject = 0;
00079     StatusCode sc = fDataProviderSvc->retrieveObject(fLocation, dataObject);
00080     if(!sc.isSuccess()) {
00081       Lib::Out out(printer());
00082       out << "OnXSvc::KeyedType<>::iterator :"
00083           << " retreiveObject failed."
00084           << Lib::endl;
00085       return new KeyedIterator< Object >();
00086     }
00087     Collection* collection = dynamic_cast<Collection*>(dataObject);
00088     if(!collection) {
00089       Lib::Out out(printer());
00090       out << "OnXSvc::KeyedType<>::iterator :"
00091           << " dynamic_cast failed."
00092           << Lib::endl;
00093       return new KeyedIterator< Object >();
00094     }
00095     return new KeyedIterator< Object >(collection);
00096   }
00097   virtual void setIterator(Lib::IIterator* aIterator) { fIterator = aIterator;}
00098 public: //OnX::IType
00099   virtual void beginVisualize() {
00100     if(!fUISvc) {
00101       fSoRegion = 0;
00102       return;
00103     }
00104     ISession* session = fUISvc->session();
00105     if(!session) {
00106       Lib::Out out(printer());
00107       out << "OnXSvc::KeyedType<>::beginVisualize :"
00108           << " can't get a ISession."
00109           << Lib::endl;
00110       fSoRegion = 0;
00111       return;
00112     }
00113     fSoRegion = fUISvc->currentSoRegion();
00114   }
00115   virtual void endVisualize() {
00116     fSoRegion = 0;
00117   }
00118   /*
00119   virtual void visualize(Lib::Identifier aIdentifier,void*) {
00120     if(!aIdentifier) return;
00121     if(!fSoCnvSvc) return;
00122     if(!fCollection) return;
00123     Object* object = (Object*)aIdentifier;
00124     // Convert it :
00125     if(!fConverter) {
00126       // Optimisation : get the converter once.
00127       fConverter = fSoCnvSvc->converter(fCLID);
00128       if(!fConverter) {
00129         Lib::Out out(printer());
00130         out << "OnXSvc::KeyedType<>::visualize :"
00131             << " converter not found for Object/CLID='"
00132             << System::typeinfoName( typeid( *fCollection ) ) << "'/'"
00133             << fCLID << "'"
00134             << Lib::endl;
00135       }
00136     }
00137     // Have a Collection with one entry.
00138     fCollection->add(object);
00139     if(fConverter) {
00140       IOpaqueAddress* addr = (IOpaqueAddress*)fSoRegion;
00141       fConverter->createRep(fCollection,addr) ;
00142     } else { // Try anyway with the generic mechanism :
00143       IOpaqueAddress* addr = 0;
00144       StatusCode sc = fSoCnvSvc->createRep(fCollection, addr);
00145       if (sc.isSuccess()) sc = fSoCnvSvc->fillRepRefs(addr,fCollection);
00146     }  
00147     fCollection->remove(object);
00148   }
00149   */
00150 public:
00151   KeyedType(const CLID& aCLID,
00152        const std::string& aType,
00153        const std::string& aLocation,
00154        IUserInterfaceSvc* aUISvc,
00155        ISoConversionSvc* aSoCnvSvc,
00156        IDataProviderSvc* aDataProviderSvc)
00157     :OnX::BaseType(aUISvc->printer())
00158     ,fCLID(aCLID)
00159     ,fType(aType)
00160     ,fLocation(aLocation)
00161     ,fIterator(0)
00162     ,fConverter(0)
00163     //,fCollection(0)
00164     ,fSoRegion(0)
00165     ,fUISvc(aUISvc)
00166     ,fSoCnvSvc(aSoCnvSvc)
00167     ,fDataProviderSvc(aDataProviderSvc){
00168 
00169     if(!fUISvc) {
00170       Lib::Out out(printer());
00171       out << "OnXSvc::KeyedType<> :"
00172           << " can't get a IUserInterfaceSvc."
00173           << Lib::endl;
00174     }
00175 
00176     //fCollection = new Collection();
00177   }
00178   virtual ~KeyedType() {
00179     //delete fCollection;
00180   }
00181   void setLocation(const std::string& aLocation) { fLocation = aLocation;}
00182   const std::string& location() const { return fLocation;}
00183 protected:
00184   bool setLocationFromSession(bool verbose = true) {
00185     if(!fUISvc) return false;
00186     ISession* session = fUISvc->session();
00187     if(!session) return false;
00188     std::string value;
00189     if(!session->parameterValue(fType+".location",value)) {
00190       if(verbose) {
00191         Lib::Out out(printer());
00192         out << "OnXSvc::KeyedType<" << fType << ">::setLocationFromSession :"
00193             << " Session parameter " << fType << ".location not found."
00194             << Lib::endl;
00195       }
00196       return false;
00197     }
00198     if(value=="") {
00199       if(verbose) {
00200         Lib::Out out(printer());
00201         out << "OnXSvc::KeyedType<" << fType << ">::setLocationFromSession :"
00202             << " Session parameter " << fType << ".location empty."
00203             << Lib::endl;
00204       }
00205       return false;
00206     }
00207     if(verbose) {
00208       Lib::Out out(printer());
00209       out << "OnXSvc::KeyedType<" << fType << ">::setLocationFromSession :"
00210           << " set location \"" << value << "\""
00211           << Lib::endl;
00212     }
00213     setLocation(value);
00214     return true;
00215   }
00216   bool attribute(const std::string& aWhat,std::string& aValue) const {
00217     aValue = "";
00218     if(!fUISvc) return false;
00219     ISession* session = fUISvc->session();
00220     if(!session) return false;
00221     return session->parameterValue(aWhat,aValue);
00222   }
00223   bool attribute(const std::string& aWhat,float& aR,float& aG,float& aB) const {
00224     aR = 0.5F;
00225     aG = 0.5F;
00226     aB = 0.5F;
00227     if(!fUISvc) return false;
00228     ISession* session = fUISvc->session();
00229     if(!session) return false;
00230     std::string value;
00231     if(!session->parameterValue(aWhat,value)) return false;
00232     double r,g,b;
00233     if(!Lib::smanip::torgb(value,r,g,b)) return false;
00234     aR = (float)r;
00235     aG = (float)g;
00236     aB = (float)b;
00237     return true;
00238   }
00239   bool modelingSolid() const {
00240     if(!fUISvc) return true;
00241     ISession* session = fUISvc->session();
00242     if(!session) return true;
00243     std::string value;
00244     if(!session->parameterValue("modeling.modeling",value)) return true;
00245     return (value=="solid" ? true : false); 
00246   }
00247 private:
00248   const CLID& fCLID;
00249   std::string fType;
00250   std::string fLocation;
00251   Lib::IIterator* fIterator;
00252   IConverter* fConverter;
00253   //Collection* fCollection;
00254 protected:  
00255   SoRegion* fSoRegion;
00256   IUserInterfaceSvc* fUISvc;
00257   ISoConversionSvc* fSoCnvSvc;
00258   IDataProviderSvc* fDataProviderSvc;
00259 };
00260 
00261 }
00262 
00263 #endif
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:00 2011 for OnXSvc by doxygen 1.4.7