FreeCAD
1/***************************************************************************
2* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* This library is free software; you can redistribute it and/or *
7* modify it under the terms of the GNU Library General Public *
8* License as published by the Free Software Foundation; either *
9* version 2 of the License, or (at your option) any later version. *
10* *
11* This library is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU Library General Public License for more details. *
15* *
16* You should have received a copy of the GNU Library General Public *
17* License along with this library; see the file COPYING.LIB. If not, *
18* write to the Free Software Foundation, Inc., 59 Temple Place, *
19* Suite 330, Boston, MA 02111-1307, USA *
20* *
21***************************************************************************/
22
23#include "PreCompiled.h"24
25#include <App/DocumentObject.h>26#include <Base/Type.h>27
28#include "DAGFilter.h"29
30
31using namespace Gui;32using namespace DAG;33
34FilterBase::FilterBase() : name(QString::fromLatin1("empty name"))35{
36
37}
38
39FilterOrigin::FilterOrigin() : FilterBase()40{
41name = QObject::tr("Origin");42}
43
44bool FilterOrigin::goFilter(const Vertex &vertexIn, const Graph &graphIn, const GraphLinkContainer &linkIn) const45{
46Base::Type originType = Base::Type::fromName("App::Origin");47assert (originType != Base::Type::badType());48//if child of origin hide.49InEdgeIterator it, itEnd;50for (boost::tie(it, itEnd) = boost::in_edges(vertexIn, graphIn); it != itEnd; ++it)51{52Vertex source = boost::source(*it, graphIn);53const GraphLinkRecord &sourceRecord = findRecord(source, linkIn);54if55(56(sourceRecord.DObject->getTypeId() == originType) &&57(boost::in_degree(vertexIn, graphIn) == 1)58)59return true;60}61return false;62}
63
64FilterTyped::FilterTyped(const std::string &typeIn) : FilterBase(), type(typeIn)65{
66name = QString::fromStdString(typeIn);67}
68
69bool FilterTyped::goFilter(const Gui::DAG::Vertex& vertexIn, const Graph& graphIn, const GraphLinkContainer& linkIn) const70{
71Q_UNUSED(graphIn);72if (type.empty())73return false;74Base::Type theType = Base::Type::fromName(type.c_str());75if (theType == Base::Type::badType())76return false;77
78const GraphLinkRecord &sourceRecord = findRecord(vertexIn, linkIn);79if (sourceRecord.DObject->getTypeId() == theType)80return true;81
82return false;83}
84
85
86