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