| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/*************************************************************************** |
| 3 |
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> * |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
|
| 25 |
#include "DAGModelGraph.h" |
| 26 |
|
| 27 |
|
| 28 |
using namespace Gui; |
| 29 |
using namespace DAG; |
| 30 |
|
| 31 |
VertexProperty::VertexProperty() |
| 32 |
: rectangle(new RectItem()) |
| 33 |
, point(new QGraphicsEllipseItem()) |
| 34 |
, visibleIcon(new QGraphicsPixmapItem()) |
| 35 |
, stateIcon(new QGraphicsPixmapItem()) |
| 36 |
, icon(new QGraphicsPixmapItem()) |
| 37 |
, text(new QGraphicsTextItem()) |
| 38 |
{ |
| 39 |
// set z values. |
| 40 |
this->rectangle->setZValue(-1000.0); |
| 41 |
this->point->setZValue(1000.0); |
| 42 |
this->visibleIcon->setZValue(0.0); |
| 43 |
this->stateIcon->setZValue(0.0); |
| 44 |
this->icon->setZValue(0.0); |
| 45 |
this->text->setZValue(0.0); |
| 46 |
} |
| 47 |
|
| 48 |
EdgeProperty::EdgeProperty() = default; |
| 49 |
|
| 50 |
bool Gui::DAG::hasRecord(const App::DocumentObject* dObjectIn, const GraphLinkContainer& containerIn) |
| 51 |
{ |
| 52 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByDObject>::type; |
| 53 |
const List& list = containerIn.get<GraphLinkRecord::ByDObject>(); |
| 54 |
List::const_iterator it = list.find(dObjectIn); |
| 55 |
return it != list.end(); |
| 56 |
} |
| 57 |
|
| 58 |
bool Gui::DAG::hasRecord( |
| 59 |
const ViewProviderDocumentObject* VPDObjectIn, |
| 60 |
const GraphLinkContainer& containerIn |
| 61 |
) |
| 62 |
{ |
| 63 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByVPDObject>::type; |
| 64 |
const List& list = containerIn.get<GraphLinkRecord::ByVPDObject>(); |
| 65 |
List::const_iterator it = list.find(VPDObjectIn); |
| 66 |
return it != list.end(); |
| 67 |
} |
| 68 |
|
| 69 |
const GraphLinkRecord& Gui::DAG::findRecord(Vertex vertexIn, const GraphLinkContainer& containerIn) |
| 70 |
{ |
| 71 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByVertex>::type; |
| 72 |
const List& list = containerIn.get<GraphLinkRecord::ByVertex>(); |
| 73 |
List::const_iterator it = list.find(vertexIn); |
| 74 |
assert(it != list.end()); |
| 75 |
return *it; |
| 76 |
} |
| 77 |
|
| 78 |
const GraphLinkRecord& Gui::DAG::findRecord( |
| 79 |
const App::DocumentObject* dObjectIn, |
| 80 |
const GraphLinkContainer& containerIn |
| 81 |
) |
| 82 |
{ |
| 83 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByDObject>::type; |
| 84 |
const List& list = containerIn.get<GraphLinkRecord::ByDObject>(); |
| 85 |
List::const_iterator it = list.find(dObjectIn); |
| 86 |
assert(it != list.end()); |
| 87 |
return *it; |
| 88 |
} |
| 89 |
|
| 90 |
const GraphLinkRecord& Gui::DAG::findRecord( |
| 91 |
const ViewProviderDocumentObject* VPDObjectIn, |
| 92 |
const GraphLinkContainer& containerIn |
| 93 |
) |
| 94 |
{ |
| 95 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByVPDObject>::type; |
| 96 |
const List& list = containerIn.get<GraphLinkRecord::ByVPDObject>(); |
| 97 |
List::const_iterator it = list.find(VPDObjectIn); |
| 98 |
assert(it != list.end()); |
| 99 |
return *it; |
| 100 |
} |
| 101 |
|
| 102 |
const GraphLinkRecord& Gui::DAG::findRecord(const RectItem* rectIn, const GraphLinkContainer& containerIn) |
| 103 |
{ |
| 104 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByRectItem>::type; |
| 105 |
const List& list = containerIn.get<GraphLinkRecord::ByRectItem>(); |
| 106 |
List::const_iterator it = list.find(rectIn); |
| 107 |
assert(it != list.end()); |
| 108 |
return *it; |
| 109 |
} |
| 110 |
|
| 111 |
const GraphLinkRecord& Gui::DAG::findRecord( |
| 112 |
const std::string& stringIn, |
| 113 |
const GraphLinkContainer& containerIn |
| 114 |
) |
| 115 |
{ |
| 116 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByUniqueName>::type; |
| 117 |
const List& list = containerIn.get<GraphLinkRecord::ByUniqueName>(); |
| 118 |
List::const_iterator it = list.find(stringIn); |
| 119 |
assert(it != list.end()); |
| 120 |
return *it; |
| 121 |
} |
| 122 |
|
| 123 |
void Gui::DAG::eraseRecord(const ViewProviderDocumentObject* VPDObjectIn, GraphLinkContainer& containerIn) |
| 124 |
{ |
| 125 |
using List = GraphLinkContainer::index<GraphLinkRecord::ByVPDObject>::type; |
| 126 |
const List& list = containerIn.get<GraphLinkRecord::ByVPDObject>(); |
| 127 |
List::iterator it = list.find(VPDObjectIn); |
| 128 |
assert(it != list.end()); |
| 129 |
containerIn.get<GraphLinkRecord::ByVPDObject>().erase(it); |
| 130 |
} |