1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-26 10:19:45 +03:00
occt/src/GraphDS/GraphDS_RelationGraph.gxx
bugmaster b311480ed5 0023024: Update headers of OCCT files
Added appropriate copyright and license information in source files
2012-03-21 19:43:04 +04:00

330 lines
9.4 KiB
Plaintext
Executable File

// Created on: 1991-09-09
// Created by: Denis PASCAL
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// except in compliance with the License. Please obtain a copy of the License
// at http://www.opencascade.org and read it completely before using this file.
//
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
//
// The Original Code and all software distributed under the License is
// distributed on an "AS IS" basis, without warranty of any kind, and the
// Initial Developer hereby disclaims all such warranties, including without
// limitation, any warranties of merchantability, fitness for a particular
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
// <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);
}