0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / MAT / MAT_Zone.cxx
CommitLineData
b311480e 1// Created on: 1993-05-05
2// Created by: Yves FRICAUD
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <MAT_Arc.hxx>
7fd59977 19#include <MAT_BasicElt.hxx>
7fd59977 20#include <MAT_Node.hxx>
42cf5bc1 21#include <MAT_SequenceOfArc.hxx>
22#include <MAT_Zone.hxx>
23#include <Standard_Type.hxx>
7fd59977 24
25e59720 25IMPLEMENT_STANDARD_RTTIEXT(MAT_Zone,Standard_Transient)
92efcf78 26
7fd59977 27//========================================================================
28// function:
29// purpose :
30//========================================================================
31MAT_Zone::MAT_Zone ()
d533dafb 32: limited(Standard_True)
33{
34}
7fd59977 35
36//========================================================================
37// function:
38// purpose :
39//========================================================================
40MAT_Zone::MAT_Zone(const Handle(MAT_BasicElt)& aBasicElt)
41{
42 Perform (aBasicElt);
43}
44
45//========================================================================
46// function: Perform
47// purpose :
48//========================================================================
49void MAT_Zone::Perform (const Handle(MAT_BasicElt)& aBasicElt)
50{
51 Handle (MAT_Node) NextNode, StartNode;
52 Handle (MAT_Arc) CurrentArc;
53
54 limited = Standard_True;
55 frontier.Clear();
56 // ------------------------------------------------------------------------
57 // Si le premier arc correspondant a la zone est Null => Sequence vide.
58 // ------------------------------------------------------------------------
59 if (aBasicElt->EndArc().IsNull()) return;
60
61 // ----------------------------
62 // Angle rentrant => Zone Vide.
63 // ----------------------------
64 // if(aBasicElt->EndArc() == aBasicElt->StartArc()) return;
65
66 // --------------------------------
67 // Initialisation de la frontier.
68 // --------------------------------
69 CurrentArc = aBasicElt->EndArc();
70 frontier.Append(CurrentArc);
71
72 // --------------------------------------------------------------------------
73 // Determination du premier noeud qui permet de construire la zone en tournant
74 // surla gauche.
75 // --------------------------------------------------------------------------
76 NextNode = NodeForTurn(CurrentArc,aBasicElt,MAT_Left);
77 StartNode = CurrentArc->TheOtherNode(NextNode);
78
79 // -------------------------------------------------------------------------
80 // Exploration du Graph toujours sur les arcs voisins a gauche jusqu'a
81 // - retour sur la Figure .
82 // - l acces a un noeud infini .
83 // (Ces deux cas correspondent a des noeuds pendants.)
84 // - retour sur l arc de depart si le basicElt est ferme.
85 // -------------------------------------------------------------------------
86
87 while (!NextNode->PendingNode() && (NextNode != StartNode)) {
88 CurrentArc = CurrentArc->Neighbour(NextNode,MAT_Left);
89 frontier.Append(CurrentArc);
90 NextNode = CurrentArc->TheOtherNode(NextNode);
91 }
92
93 // -----------------------------------------------------------------------
94 // Si NextNode est a l infini : exploration du graph a partir du StartArc
95 // sur <aBasicElt>.
96 // exploration sur les arcs voisins a droite.
97 // Sinon => Fin.
98 // -----------------------------------------------------------------------
99
100 if (NextNode->Infinite()) {
101 limited = Standard_False;
102 CurrentArc = aBasicElt->StartArc();
103 frontier.Append(CurrentArc);
104 // --------------------------------------------------------------------------
105 // Determination du premier noeud qui permet de construire la zone en
106 //tournan surla droite.
107 // --------------------------------------------------------------------------
108 NextNode = NodeForTurn(CurrentArc,aBasicElt,MAT_Right);
109
110 // -----------------------------------------------------
111 // Cette branche est aussi terminee par un noeud infini.
112 // -----------------------------------------------------
113 while (!NextNode->Infinite()) {
114 CurrentArc = CurrentArc->Neighbour(NextNode,MAT_Right);
115 frontier.Append(CurrentArc);
116 NextNode = CurrentArc->TheOtherNode(NextNode);
117 }
118 }
119}
120
121//========================================================================
122// function: NumberOfArcs
123// purpose :
124//========================================================================
125Standard_Integer MAT_Zone::NumberOfArcs()const
126{
127 return frontier.Length();
128}
129
130//========================================================================
131// function: ArcOnFrontier
132// purpose :
133//========================================================================
134Handle(MAT_Arc) MAT_Zone::ArcOnFrontier(const Standard_Integer Index)const
135{
136 return frontier.Value(Index);
137}
138
139//========================================================================
140// function: NoEmptyZone
141// purpose :
142//========================================================================
143Standard_Boolean MAT_Zone::NoEmptyZone()const
144{
145 return (!frontier.IsEmpty());
146}
147
148//========================================================================
149// function: Limited
150// purpose :
151//========================================================================
152Standard_Boolean MAT_Zone::Limited()const
153{
154 return limited;
155}
156
157//========================================================================
158// function:
159// purpose :
160//========================================================================
161Handle(MAT_Node) MAT_Zone::NodeForTurn (const Handle(MAT_Arc)& anArc,
162 const Handle(MAT_BasicElt)& aBE,
163 const MAT_Side aSide)
164 const
165{
166 Handle(MAT_Arc) NeighbourArc;
167 Handle(MAT_Node) NodeSol ;
168
169 NodeSol = anArc->FirstNode();
170 NeighbourArc = anArc->Neighbour(NodeSol,aSide);
171 if (NeighbourArc.IsNull()) {
172 NodeSol = anArc->SecondNode();
173 NeighbourArc = anArc->Neighbour(NodeSol,aSide);
174 }
175 if (NeighbourArc.IsNull()) {
176 return NodeSol;
177 }
178 if (NeighbourArc->FirstElement() == aBE) {
179 return NodeSol;
180 }
181 else if (NeighbourArc->SecondElement() == aBE) {
182 return NodeSol;
183 }
184 else {
185 return anArc->TheOtherNode(NodeSol);
186 }
187}