1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-20 11:54:07 +03:00
occt/src/GraphDS/GraphDS_RelationGraph.gxx
abv ed4415982c 0024624: Lost word in license statement in source files
License statement text corrected; compiler warnings caused by Bison 2.41 disabled for MSVC; a few other compiler warnings on 54-bit Windows eliminated by appropriate type cast
Wrong license statements corrected in several files.
Copyright and license statements added in XSD and GLSL files.
Copyright year updated in some files.
Obsolete documentation files removed from DrawResources.
2014-03-25 16:38:55 +04:00

326 lines
9.1 KiB
Plaintext

// Created on: 1991-09-09
// Created by: Denis PASCAL
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// <dp>
#include <Standard_NoSuchObject.hxx>
#include <Standard_DomainError.hxx>
#include <TColStd_MapIteratorOfMapOfTransient.hxx>
#include <GraphDS_DataMapIteratorOfEntityRoleMap.hxx>
//=======================================================================
//function : GraphDS_RelationGraph
//purpose :
//=======================================================================
GraphDS_RelationGraph::GraphDS_RelationGraph ()
{
}
//=======================================================================
//function : GraphDS_RelationGraph
//purpose :
//=======================================================================
GraphDS_RelationGraph::GraphDS_RelationGraph
(const GraphDS_RelationGraph& other)
{
myEntities = other.myEntities;
myRelations = other.myRelations;
}
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsEmpty () const
{
return myEntities.Extent() ==0;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void GraphDS_RelationGraph::Clear ()
{
myEntities.Clear();
myRelations.Clear();
}
//=======================================================================
//function : Contains
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::Contains
(const Handle(GraphDS_Entity)& V) const
{
return myEntities.Contains(V);
}
//=======================================================================
//function : IsInRelation
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsInRelation
(const Handle(GraphDS_Entity)& V) const
{
return (V->HasRelation());
}
//=======================================================================
//function : IsInput
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsInput
(const Handle(GraphDS_Entity)& V) const
{
return !IsDependent(V);
}
//=======================================================================
//function : IsOutput
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsOutput
(const Handle(GraphDS_Entity)& V) const
{
if (V->GetRelations().IsEmpty()) return Standard_True;
TColStd_MapIteratorOfMapOfTransient it (V->GetRelations());
for (;it.More();it.Next()) {
if (Handle(GraphDS_Relation)::DownCast(it.Key())->IsOutput(V)) return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : IsDependent
//purpose : il est seulement sortie d'une au moins de ses relations
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsDependent
(const Handle(GraphDS_Entity)& E) const
{
if (E->GetRelations().IsEmpty()) return Standard_False;
TColStd_MapIteratorOfMapOfTransient it (E->GetRelations());
for (;it.More();it.Next()) {
if (Handle(GraphDS_Relation)::DownCast(it.Key())->IsOutput(E)) {
if (!Handle(GraphDS_Relation)::DownCast(it.Key())->IsInput(E))return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : Contains
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::Contains
(const Handle(GraphDS_Relation)& R) const
{
return (myRelations.Contains(R));
}
//=======================================================================
//function : NbEntities
//purpose :
//=======================================================================
Standard_Integer GraphDS_RelationGraph::NbEntities() const
{
return myEntities.Extent();
}
//=======================================================================
//function : NbRelations
//purpose :
//=======================================================================
Standard_Integer GraphDS_RelationGraph::NbRelations() const
{
return myRelations.Extent();
}
//=======================================================================
//function : AddEntity
//purpose :
//=======================================================================
Handle(GraphDS_Entity) GraphDS_RelationGraph::AddEntity
(const GraphDS_Item& item)
{
Handle(GraphDS_Entity) entity = new GraphDS_Entity(item);
myEntities.Add(entity);
return entity;
}
//=======================================================================
//function : RemoveEntity
//purpose : Removes an Entity of the relation graph
//=======================================================================
void GraphDS_RelationGraph::RemoveEntity
(const Handle(GraphDS_Entity)& E)
{
if (E->HasRelation()) Standard_DomainError::Raise();
myEntities.Remove(E);
}
//=======================================================================
//function : AddRelation
//purpose :
//=======================================================================
Handle(GraphDS_Relation) GraphDS_RelationGraph::AddRelation
(const GraphDS_Attribute& att)
{
Handle(GraphDS_Relation) newrel = new GraphDS_Relation(att);
myRelations.Add(newrel);
return newrel;
}
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
Standard_Boolean GraphDS_RelationGraph::IsEmpty
(const Handle(GraphDS_Relation)& R) const
{
return R->IsEmpty();
}
//=======================================================================
//function : Add
//purpose : InputAndOutput
//=======================================================================
void GraphDS_RelationGraph::Add
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E)
{
Add (R,E,GraphDS_InputAndOutput);
}
//=======================================================================
//function : AddInput
//purpose : OnlyInput
//=======================================================================
void GraphDS_RelationGraph::AddInput
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E)
{
Add (R,E,GraphDS_OnlyInput);
}
//=======================================================================
//function : AddOutput
//purpose : OnlyOutput
//=======================================================================
void GraphDS_RelationGraph::AddOutput
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E)
{
Add (R,E,GraphDS_OnlyOutput);
}
//=======================================================================
//function : Add
//purpose :
//=======================================================================
void GraphDS_RelationGraph::Add
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E,
const GraphDS_EntityRole role)
{
R->Add(E,role);
E->Add(R);
}
//=======================================================================
//function : SetRole
//purpose :
//=======================================================================
void GraphDS_RelationGraph::SetRole
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E,
const GraphDS_EntityRole role)
{
R->SetRole(E,role);
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
void GraphDS_RelationGraph::Remove
(const Handle(GraphDS_Relation)& R,
const Handle(GraphDS_Entity)& E)
{
R->Remove(E);
E->Remove(R);
}
//=======================================================================
//function : RemoveRelation
//purpose : Removes a relation of the relation graph
//=======================================================================
void GraphDS_RelationGraph::RemoveRelation
(const Handle(GraphDS_Relation)& R)
{
Handle(GraphDS_Entity) ENT;
GraphDS_DataMapIteratorOfEntityRoleMap it;
for (it.Initialize(R->GetEntities());it.More();it.Next()) {
ENT = Handle(GraphDS_Entity)::DownCast(it.Key());
ENT->Remove(R);
}
myRelations.Remove(R);
}