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

In This Package:

Type.h

Go to the documentation of this file.
00001 #ifndef OnXSvc_Type_h
00002 #define OnXSvc_Type_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/ObjectVector.h>
00021 
00022 namespace OnXSvc {
00023 
00024 template <class Object> 
00025 class Iterator : 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 ObjectVector<Object> Collection;
00044   Iterator(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 Type : public OnX::BaseType {
00054 private:
00055   typedef ObjectVector<Object> 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::Type<>::iterator :"
00072           << " no data provider found."
00073           << Lib::endl;
00074       return new Iterator< 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::Type<>::iterator :"
00083           << " retreiveObject failed."
00084           << Lib::endl;
00085       return new Iterator< Object >();
00086     }
00087     Collection* collection = dynamic_cast<Collection*>(dataObject);
00088     if(!collection) {
00089       Lib::Out out(printer());
00090       out << "OnXSvc::Type<>::iterator :"
00091           << " dynamic_cast failed."
00092           << Lib::endl;
00093       return new Iterator< Object >();
00094     }
00095     return new Iterator< 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::Type<>::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   /* FIXME : the below does not work because a ObjectVector::remove delete the 
00119              object !
00120   virtual void visualize(Lib::Identifier aIdentifier,void*) {
00121     if(!aIdentifier) return;
00122     if(!fSoCnvSvc) return;
00123     if(!fCollection) return;
00124     Object* object = (Object*)aIdentifier;
00125     // Convert it :
00126     if(!fConverter) {
00127       // Optimisation : get the converter once.
00128       fConverter = fSoCnvSvc->converter(fCLID);
00129       if(!fConverter) {
00130         Lib::Out out(printer());
00131         out << "OnXSvc::Type<>::visualize :"
00132             << " converter not found for Object/CLID='"
00133             << System::typeinfoName( typeid( *fCollection ) ) << "'/'"
00134             << fCLID << "'"
00135             << Lib::endl;
00136       }
00137     }
00138     // Have a Collection with one entry.
00139     fCollection->add(object);
00140     if(fConverter) {
00141       IOpaqueAddress* addr = (IOpaqueAddress*)fSoRegion;
00142       fConverter->createRep(fCollection,addr) ;
00143     } else { // Try anyway with the generic mechanism :
00144       IOpaqueAddress* addr = 0;
00145       StatusCode sc = fSoCnvSvc->createRep(fCollection, addr);
00146       if (sc.isSuccess()) sc = fSoCnvSvc->fillRepRefs(addr,fCollection);
00147     }  
00148     fCollection->remove(object);
00149   }
00150   */
00151 public:
00152   Type(const CLID& aCLID,
00153        const std::string& aType,
00154        const std::string& aLocation,
00155        IUserInterfaceSvc* aUISvc,
00156        ISoConversionSvc* aSoCnvSvc,
00157        IDataProviderSvc* aDataProviderSvc)
00158     :OnX::BaseType(aUISvc->printer())
00159     ,fCLID(aCLID)
00160     ,fType(aType)
00161     ,fLocation(aLocation)
00162     ,fIterator(0)
00163     ,fConverter(0)
00164     //,fCollection(0)
00165     ,fSoRegion(0)
00166     ,fUISvc(aUISvc)
00167     ,fSoCnvSvc(aSoCnvSvc)
00168     ,fDataProviderSvc(aDataProviderSvc) {
00169 
00170     if(!fUISvc) {
00171       Lib::Out out(printer());
00172       out << "OnXSvc::Type<> :"
00173           << " can't get a IUserInterfaceSvc."
00174           << Lib::endl;
00175     }
00176 
00177     //fCollection = new Collection();
00178   }
00179   virtual ~Type() {
00180     //delete fCollection;
00181   }
00182   void setLocation(const std::string& aLocation) { fLocation = aLocation;}
00183   const std::string& location() const { return fLocation;}
00184 protected:
00185   bool setLocationFromSession(bool verbose = true) {
00186     if(!fUISvc) return false;
00187     ISession* session = fUISvc->session();
00188     if(!session) return false;
00189     std::string value;
00190     if(!session->parameterValue(fType+".location",value)) {
00191       if(verbose) {
00192         Lib::Out out(printer());
00193         out << "OnXSvc::Type<" << fType << ">::setLocationFromSession :"
00194             << " Session parameter " << fType << ".location not found."
00195             << Lib::endl;
00196       }
00197       return false;
00198     }
00199     if(value=="") {
00200       if(verbose) {
00201         Lib::Out out(printer());
00202         out << "OnXSvc::Type<" << fType << ">::setLocationFromSession :"
00203             << " Session parameter " << fType << ".location empty."
00204             << Lib::endl;
00205       }
00206       return false;
00207     }
00208     if(verbose) {
00209       Lib::Out out(printer());
00210       out << "OnXSvc::Type<" << fType << ">::setLocationFromSession :"
00211           << " set location \"" << value << "\""
00212           << Lib::endl;
00213     }
00214     setLocation(value);
00215     return true;
00216   }
00217   bool attribute(const std::string& aWhat,std::string& aValue) const {
00218     aValue = "";
00219     if(!fUISvc) return false;
00220     ISession* session = fUISvc->session();
00221     if(!session) return false;
00222     return session->parameterValue(aWhat,aValue);
00223   }
00224   bool attribute(const std::string& aWhat,float& aR,float& aG,float& aB) const {
00225     aR = 0.5F;
00226     aG = 0.5F;
00227     aB = 0.5F;
00228     if(!fUISvc) return false;
00229     ISession* session = fUISvc->session();
00230     if(!session) return false;
00231     std::string value;
00232     if(!session->parameterValue(aWhat,value)) return false;
00233     double r,g,b;
00234     if(!Lib::smanip::torgb(value,r,g,b)) return false;
00235     aR = (float)r;
00236     aG = (float)g;
00237     aB = (float)b;
00238     return true;
00239   }
00240   bool modelingSolid() const {
00241     if(!fUISvc) return true;
00242     ISession* session = fUISvc->session();
00243     if(!session) return true;
00244     std::string value;
00245     if(!session->parameterValue("modeling.modeling",value)) return true;
00246     return (value=="solid" ? true : false); 
00247   }
00248 private:
00249   const CLID& fCLID;
00250   std::string fType;
00251   std::string fLocation;
00252   Lib::IIterator* fIterator;
00253   IConverter* fConverter;
00254   //Collection* fCollection;
00255 protected:  
00256   SoRegion* fSoRegion;
00257   IUserInterfaceSvc* fUISvc;
00258   ISoConversionSvc* fSoCnvSvc;
00259   IDataProviderSvc* fDataProviderSvc;
00260 };
00261 
00262 
00263 }
00264 
00265 #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