PropertyLinks.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef APP_PROPERTYLINKS_H
00025 #define APP_PROPERTYLINKS_H
00026 
00027 // Std. configurations
00028 
00029 
00030 #include <vector>
00031 #include <string>
00032 #include "Property.h"
00033 
00034 namespace Base {
00035 class Writer;
00036 }
00037 
00038 namespace App
00039 {
00040 class DocumentObject;
00041 
00042 
00046 class AppExport PropertyLink : public Property
00047 {
00048     TYPESYSTEM_HEADER();
00049 
00050 public:
00055     PropertyLink();
00056 
00061     ~PropertyLink();
00062 
00065     void setValue(App::DocumentObject *);
00066 
00069     App::DocumentObject * getValue(void) const;
00070 
00073     App::DocumentObject * getValue(Base::Type t) const;
00074 
00077     template <typename _type>
00078     inline _type getValue(void) const {
00079         return _pcLink ? dynamic_cast<_type>(_pcLink) : 0;
00080     }
00081 
00082     virtual PyObject *getPyObject(void);
00083     virtual void setPyObject(PyObject *);
00084 
00085     virtual void Save (Base::Writer &writer) const;
00086     virtual void Restore(Base::XMLReader &reader);
00087 
00088     virtual Property *Copy(void) const;
00089     virtual void Paste(const Property &from);
00090 
00091     virtual unsigned int getMemSize (void) const{
00092         return sizeof(App::DocumentObject *);
00093     }
00094 
00095 protected:
00096     App::DocumentObject *_pcLink;
00097 };
00098 
00099 
00106 class AppExport PropertyLinkSub: public Property
00107 {
00108     TYPESYSTEM_HEADER();
00109 
00110 public:
00115     PropertyLinkSub();
00116 
00121     ~PropertyLinkSub();
00122 
00125     void setValue(App::DocumentObject *,const std::vector<std::string> &SubList=std::vector<std::string>());
00126 
00129     App::DocumentObject * getValue(void) const;
00130 
00132     const std::vector<std::string>& getSubValues(void) const;
00133 
00135     std::vector<std::string> getSubValuesStartsWith(const char*) const;
00136 
00139     App::DocumentObject * getValue(Base::Type t) const;
00140 
00143     template <typename _type>
00144     inline _type getValue(void) const {
00145         return _pcLinkSub ? dynamic_cast<_type>(_pcLinkSub) : 0;
00146     }
00147 
00148     virtual PyObject *getPyObject(void);
00149     virtual void setPyObject(PyObject *);
00150 
00151     virtual void Save (Base::Writer &writer) const;
00152     virtual void Restore(Base::XMLReader &reader);
00153 
00154     virtual Property *Copy(void) const;
00155     virtual void Paste(const Property &from);
00156 
00157     virtual unsigned int getMemSize (void) const{
00158         return sizeof(App::DocumentObject *);
00159     }
00160 
00161 protected:
00162     App::DocumentObject *_pcLinkSub;
00163     std::vector<std::string> _cSubList;
00164 
00165 };
00166 
00167 class AppExport PropertyLinkList: public PropertyLists
00168 {
00169     TYPESYSTEM_HEADER();
00170 
00171 public:
00176     PropertyLinkList();
00177 
00182     virtual ~PropertyLinkList();
00183 
00184     virtual void setSize(int newSize);
00185     virtual int getSize(void) const;
00186 
00189     void setValue(DocumentObject*);
00190     void setValues(const std::vector<DocumentObject*>&);
00191 
00193     DocumentObject* operator[] (const int idx) const {
00194         return _lValueList.operator[] (idx);
00195     }
00196 
00197 
00198     void  set1Value (const int idx, DocumentObject* value) {
00199         _lValueList.operator[] (idx) = value;
00200     }
00201 
00202     const std::vector<DocumentObject*> &getValues(void) const {
00203         return _lValueList;
00204     }
00205 
00206     virtual PyObject *getPyObject(void);
00207     virtual void setPyObject(PyObject *);
00208 
00209     virtual void Save (Base::Writer &writer) const;
00210     virtual void Restore(Base::XMLReader &reader);
00211 
00212     virtual Property *Copy(void) const;
00213     virtual void Paste(const Property &from);
00214 
00215     virtual unsigned int getMemSize (void) const;
00216 
00217 private:
00218     std::vector<DocumentObject*> _lValueList;
00219 };
00220 
00221 class AppExport PropertyLinkSubList: public PropertyLists
00222 {
00223     TYPESYSTEM_HEADER();
00224 
00225 public:
00230     PropertyLinkSubList();
00231 
00236     virtual ~PropertyLinkSubList();
00237 
00238     struct SubSet {
00239         SubSet(DocumentObject*o,const char*s):obj(o),sub(s){}
00240         SubSet(DocumentObject*o,const std::string &s):obj(o),sub(s.c_str()){}
00241         DocumentObject* obj;
00242         const char*     sub;
00243     };
00244 
00245     virtual void setSize(int newSize);
00246     virtual int getSize(void) const;
00247 
00250     void setValue(DocumentObject*,const char*);
00251     void setValues(const std::vector<DocumentObject*>&,const std::vector<const char*>&);
00252     void setValues(const std::vector<DocumentObject*>&,const std::vector<std::string>&);
00253 
00254     // index operator
00255     SubSet operator[] (const int idx) const {
00256         return SubSet(_lValueList.operator[] (idx),_lSubList.operator [](idx));
00257     }
00258 
00259     const std::vector<DocumentObject*> &getValues(void) const {
00260         return _lValueList;
00261     }
00262 
00263     const std::vector<std::string> &getSubValues(void) const {
00264         return _lSubList;
00265     }
00266 
00267     virtual PyObject *getPyObject(void);
00268     virtual void setPyObject(PyObject *);
00269 
00270     virtual void Save (Base::Writer &writer) const;
00271     virtual void Restore(Base::XMLReader &reader);
00272 
00273     virtual Property *Copy(void) const;
00274     virtual void Paste(const Property &from);
00275 
00276     virtual unsigned int getMemSize (void) const;
00277 
00278 private:
00279     std::vector<DocumentObject*> _lValueList;
00280     std::vector<std::string>     _lSubList;
00281 };
00282 
00283 } // namespace App
00284 
00285 
00286 #endif // APP_PROPERTYLINKS_H

Generated on Wed Nov 23 19:00:31 2011 for FreeCAD by  doxygen 1.6.1