SelectionFilter.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 Juergen Riegel  (FreeCAD@juergen-riegel.net>       *
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 GUI_SelectionFilter_H
00025 #define GUI_SelectionFilter_H
00026 
00027 #include <string>
00028 #include <CXX/Extensions.hxx>
00029 #include "Selection.h"
00030 
00031 namespace App {
00032     class DocumentObject;
00033 }
00034 
00035 namespace Gui {
00036     struct Node_Block;
00037     
00038 
00049 class GuiExport SelectionFilter 
00050 {
00051 
00052 public:
00054     SelectionFilter(const char* filter);
00055     SelectionFilter(const std::string& filter);
00056     virtual ~SelectionFilter();
00057 
00059     void setFilter(const char* filter);
00065     bool match(void);
00071     bool test(App::DocumentObject*pObj, const char*sSubName);
00072 
00073     void addError(const char* e);
00074  
00075     friend class SelectionSingleton;
00076 
00077     std::vector<std::vector<SelectionObject> > Result;
00078 
00080     bool isValid(void) const {return Ast;}
00081 
00082 protected:
00083     std::string Filter;
00084     std::string Errors;
00085     bool parse(void);
00086 
00087     Node_Block *Ast;
00088 
00089 };
00090 
00099 class GuiExport SelectionFilterGate: public SelectionGate
00100 {
00101 public:
00103     SelectionFilterGate(const char* filter);
00104     SelectionFilterGate(SelectionFilter* filter);
00105     ~SelectionFilterGate();
00106     virtual bool allow(App::Document*,App::DocumentObject*, const char*);
00107 
00108 protected:
00109     SelectionFilter *Filter;
00110 };
00111 
00117 class SelectionFilterPy : public Py::PythonExtension<SelectionFilterPy> 
00118 {
00119 private:
00120     SelectionFilter filter;
00121 
00122 public:
00123     static void init_type(void);    // announce properties and methods
00124 
00125     SelectionFilterPy(const std::string&);
00126     ~SelectionFilterPy();
00127 
00128     Py::Object repr();
00129     Py::Object match(const Py::Tuple&);
00130     Py::Object result(const Py::Tuple&);
00131     Py::Object test(const Py::Tuple&);
00132 
00133 private:
00134     static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
00135 };
00136 
00137 // === Abstract syntax tree (AST) ===========================================
00138 
00139 struct Node_Slice 
00140 {
00141     Node_Slice(int min=1,int max=INT_MAX):Min(min),Max(max){}
00142     int Min,Max;
00143 
00144 };
00145 
00146 
00147 struct Node_Object 
00148 {
00149     Node_Object(std::string *type,std::string *subname,Node_Slice* slc )
00150         :Slice(slc)
00151     {
00152         ObjectType = Base::Type::fromName(type->c_str());
00153         delete (type);
00154         if(subname){
00155             SubName = *subname;
00156             delete subname;
00157         }
00158     }
00159     ~Node_Object(){
00160         delete Slice;
00161     }
00162     Base::Type ObjectType;
00163     Node_Slice  *Slice;
00164     std::string SubName;
00165 };
00166 
00167 struct Node_Block 
00168 {
00169     Node_Block(Node_Object* obj){Objects.push_back(obj);}
00170     std::vector< Node_Object *> Objects;
00171 };
00172 
00173 
00174 } // namespace Gui
00175 
00176 
00177 #endif // GUI_SelectionFilter_H
00178 

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