SelectionObject.cpp

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 #include "PreCompiled.h"
00025 
00026 #include <strstream>
00027 
00028 #include <App/Application.h>
00029 #include <App/Document.h>
00030 #include <App/DocumentObject.h>
00031 #include <Base/Interpreter.h>
00032 
00033 #include "SelectionObject.h"
00034 #include "SelectionObjectPy.h"
00035 #include "Application.h"
00036 
00037 using namespace Gui;
00038 
00039 
00040 TYPESYSTEM_SOURCE_ABSTRACT(Gui::SelectionObject, Base::BaseClass)
00041 
00042 SelectionObject::SelectionObject()
00043 {
00044 }
00045 
00046 //SelectionObject::SelectionObject( const Gui::SelectionSingleton::SelObj &Obj )
00047 //{
00048 //      // moving the information over
00049 //      // no pointer is copied, cause is to dangerous to keep pointers to 
00050 //      // the document outside....
00051 //      DocName  = Obj.DocName;
00052 //      FeatName = Obj.FeatName;
00053 //      SubName  = Obj.SubName;
00054 //      TypeName = Obj.TypeName;
00055 //      x = Obj.x;
00056 //      y = Obj.y;
00057 //      z = Obj.z;
00058 //
00059 //}
00060 
00061 SelectionObject::~SelectionObject()
00062 {
00063 }
00064 
00065 const App::DocumentObject * SelectionObject::getObject(void) const
00066 {
00067     if (DocName != "") {
00068         App::Document *doc = App::GetApplication().getDocument(DocName.c_str());
00069         if (doc && FeatName != "")
00070             return doc->getObject(FeatName.c_str());
00071     }
00072     return 0;
00073 }
00074 
00075 App::DocumentObject * SelectionObject::getObject(void) 
00076 {
00077     if (DocName != "") {
00078         App::Document *doc = App::GetApplication().getDocument(DocName.c_str());
00079         if (doc && FeatName != "")
00080             return doc->getObject(FeatName.c_str());
00081     }
00082     return 0;
00083 }
00084 
00085 bool SelectionObject::isObjectTypeOf(const Base::Type& typeId) const
00086 {
00087     const App::DocumentObject* obj = getObject();
00088     return (obj && obj->getTypeId().isDerivedFrom(typeId));
00089 }
00090 
00091 std::string SelectionObject::getAsPropertyLinkSubString(void)const
00092 {
00093     std::string buf;
00094     buf += "(App.";
00095     buf += "ActiveDocument";//getObject()->getDocument()->getName(); 
00096     buf += ".";
00097     buf += getObject()->getNameInDocument(); 
00098     buf += ",[";
00099     for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
00100         buf += "\""; 
00101         buf += *it; 
00102         buf += "\"";
00103         if(it != --SubNames.end())
00104             buf += ",";
00105     }
00106     buf += "])";
00107    
00108     return buf;
00109 }
00110 
00111 
00112 PyObject* SelectionObject::getPyObject()
00113 {
00114     return new SelectionObjectPy(new SelectionObject(*this));
00115 }
00116 

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