0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / TNaming / TNaming_Identifier.cxx
CommitLineData
b311480e 1// Created on: 1997-03-04
2// Created by: Yves FRICAUD
3// Copyright (c) 1997-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 <TDF_ChildIterator.hxx>
19#include <TDF_Label.hxx>
20#include <TNaming_Identifier.hxx>
21#include <TNaming_Iterator.hxx>
7fd59977 22#include <TNaming_Localizer.hxx>
42cf5bc1 23#include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
24#include <TNaming_MapOfNamedShape.hxx>
7fd59977 25#include <TNaming_NamedShape.hxx>
7fd59977 26#include <TNaming_Tool.hxx>
42cf5bc1 27#include <TNaming_UsedShapes.hxx>
28#include <TopoDS_Shape.hxx>
7fd59977 29#include <TopTools_MapIteratorOfMapOfShape.hxx>
42cf5bc1 30#include <TopTools_MapOfShape.hxx>
7fd59977 31
32//#define MDTV_DEB_IDF
0797d9d3 33#ifdef OCCT_DEBUG_IDF
7fd59977 34#include <TCollection_AsciiString.hxx>
35#include <TDF_Tool.hxx>
36#include <BRepTools.hxx>
37
38//unreferenced function, commented
39/*static void ModDbgTools_Write(const TopoDS_Shape& shape,
40 const Standard_CString filename)
41{
42 ofstream save;
43 save.open(filename);
44 save << "DBRep_DrawableShape" << endl << endl;
45 if(!shape.IsNull()) BRepTools::Write(shape, save);
46 save.close();
47}
48
49static void ModDbgTools_WriteCurrentShape(const Handle(TNaming_NamedShape) & NS)
50{
51 TCollection_AsciiString entry;
52 TDF_Tool::Entry(NS->Label(), entry);
53 if (!NS.IsNull())
54 {
55 TopoDS_Shape Sh = TNaming_Tool::CurrentShape (NS);
56 if(!Sh.IsNull()) {
57 TCollection_AsciiString Entry = entry.Cat("_Cur.brep");
58 ModDbgTools_Write(Sh, Entry.ToCString());
59 }
60 else
61 cout << "ModDbgTools::Write>>> TopoDS_Shape IS NULL on Entry = "<< entry << endl;
62 }
63 else
64 cout << "ModDbgTools::Write>>> CurrentShape of TNaming_NamedShape IS NULL on Entry = "<< entry << endl;
65}*/
66#endif
67
68//=======================================================================
69//function : TNaming_Identifier
70//purpose :
71//=======================================================================
72
73TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
74 const TopoDS_Shape& S,
75 const TopoDS_Shape& Context,
258ff83b 76 const Standard_Boolean /*OneOnly*/)
77:myTDFAcces(LabAcces), myShape(S),
7fd59977 78myDone(Standard_False),myIsFeature(Standard_False)
0ddd904c
S
79{
80 Init(Context);
81}
82
83//=======================================================================
84//function : TNaming_Identifier
85//purpose :
86//=======================================================================
87
88TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
89 const TopoDS_Shape& S,
90 const Handle(TNaming_NamedShape)& ContextNS,
258ff83b 91 const Standard_Boolean /*OneOnly*/)
92:myTDFAcces(LabAcces), myShape(S),
0ddd904c 93myDone(Standard_False),myIsFeature(Standard_False)
0ddd904c
S
94{
95 const TopoDS_Shape& aContext = TNaming_Tool::GetShape (ContextNS);
96 Init(aContext);
97}
98
99//=======================================================================
100//function : Init
101//purpose :
102//=======================================================================
103void TNaming_Identifier::Init(const TopoDS_Shape& Context)
7fd59977 104{
105 Handle(TNaming_UsedShapes) US;
0ddd904c 106 myTDFAcces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
7fd59977 107
108 TNaming_Localizer Localizer;
0ddd904c 109 Localizer.Init (US,myTDFAcces.Transaction());
7fd59977 110
111 Handle(TNaming_NamedShape) NS;
0ddd904c 112 NS = TNaming_Tool::NamedShape(myShape, myTDFAcces);
7fd59977 113 if (NS.IsNull()) {
0ddd904c 114 AncestorIdentification(Localizer, Context);
7fd59977 115 return;
116 }
0797d9d3 117#ifdef OCCT_DEBUG_IDF
7fd59977 118 TCollection_AsciiString entry;
119 TDF_Tool::Entry(NS->Label(), entry);
120 cout << "Identifier:: (S) Label = " << entry <<endl;
121#endif
122 //-------------------------------------
123 // S est New dans un NamedShape
124 //-------------------------------------
125 TNaming_Evolution Evol = NS->Evolution();
126 if (Evol == TNaming_PRIMITIVE) {
127 PrimitiveIdentification(Localizer,NS);
128 }
129 else if (Evol == TNaming_GENERATED) {
130 GeneratedIdentification(Localizer,NS);
131 }
132 else {
133 Identification(Localizer,NS);
134 }
0ddd904c 135}
7fd59977 136
137//=======================================================================
138//function : Type
139//purpose :
140//=======================================================================
141
142TNaming_NameType TNaming_Identifier::Type() const
143{
144 return myType;
145}
146
147//=======================================================================
148//function : IsDone
149//purpose :
150//=======================================================================
151
152Standard_Boolean TNaming_Identifier::IsDone() const
153{
154 return myDone;
155}
156
157
158//=======================================================================
159//function : IsFeature
160//purpose :
161//=======================================================================
162
163Standard_Boolean TNaming_Identifier::IsFeature()
164{
165 return myIsFeature;
166}
167
168
169//=======================================================================
170//function : Feature
171//purpose :
172//=======================================================================
173
174Handle(TNaming_NamedShape) TNaming_Identifier::Feature() const
175{
176 return myPrimitiveArgs.First();
177}
178
179
180//=======================================================================
181//function : InitArgs
182//purpose :
183//=======================================================================
184
185void TNaming_Identifier::InitArgs()
186{
187}
188
189
190//=======================================================================
191//function : MoreArgs
192//purpose :
193//=======================================================================
194
195Standard_Boolean TNaming_Identifier::MoreArgs() const
196{
197 return (!myPrimitiveArgs.IsEmpty() || !myShapeArgs.IsEmpty());
198}
199
200//=======================================================================
201//function : ArgIsFeature
202//purpose :
203//=======================================================================
204
205Standard_Boolean TNaming_Identifier::ArgIsFeature() const
206{
207 return (!myPrimitiveArgs.IsEmpty());
208}
209
210//=======================================================================
211//function : Next
212//purpose :
213//=======================================================================
214
215void TNaming_Identifier::NextArg()
216{
217 if (!myPrimitiveArgs.IsEmpty()) myPrimitiveArgs.RemoveFirst();
218 else if (!myShapeArgs .IsEmpty()) myShapeArgs .RemoveFirst();
219}
220
221//=======================================================================
222//function : FeatureArg
223//purpose :
224//=======================================================================
225
226Handle(TNaming_NamedShape) TNaming_Identifier::FeatureArg()
227{
228 return myPrimitiveArgs.First();
229}
230
231
232//=======================================================================
233//function : ShapeArg
234//purpose :
235//=======================================================================
236
237TopoDS_Shape TNaming_Identifier::ShapeArg()
238{
239 return myShapeArgs.First();
240}
241
242
243//=======================================================================
244//function : ShapeContext
245//purpose :
246//=======================================================================
247
248TopoDS_Shape TNaming_Identifier::ShapeContext() const
249{
250 const TopoDS_Shape& S = myShapeArgs.First();
251 TopoDS_Shape SC;
252 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(S,myTDFAcces);
253 TNaming_Localizer::FindShapeContext (NS, S, SC); // szy ==> added par. S
254 return SC;
255}
256
257
258//=======================================================================
857ffd5e 259//function : Handle(TNaming_NamedShape)
7fd59977 260//purpose :
261//=======================================================================
262
263Handle(TNaming_NamedShape) TNaming_Identifier::NamedShapeOfGeneration() const
264{
265 return myNSContext;
266}
267
268//=======================================================================
269//function : AncestorIdentification
270//purpose :
271//=======================================================================
272
273void TNaming_Identifier::AncestorIdentification(TNaming_Localizer& Localizer,
274 const TopoDS_Shape& Context)
275{
276 TopTools_MapOfShape AncInFeature;
277 if (Context.IsNull()) {
278 myType = TNaming_UNKNOWN;
279 myDone = 0;
280 return;
281 }
282 Localizer.FindFeaturesInAncestors (myShape, Context, AncInFeature);
283
284 if (AncInFeature.IsEmpty()) {
285 myDone = 0;
286 return;
287 }
288 myType = TNaming_INTERSECTION;
289 TopTools_MapIteratorOfMapOfShape itS(AncInFeature);
290 for (; itS.More(); itS.Next()) myShapeArgs.Append(itS.Key());
291 myDone = 1;
292}
293
294//=======================================================================
295//function : Imported
296//purpose :
297//=======================================================================
298
299Standard_Boolean IsImported(const Handle(TNaming_NamedShape)& NS)
300{
301 TDF_Label Lab = NS->Label();
302 TDF_Label Father = Lab.Father();
303 for (TDF_ChildIterator cit(Father); cit.More(); cit.Next()) {
304 if (cit.Value() != Lab) return 0;
305 }
306
307 TNaming_Iterator it(NS);
308 if (!it.More()) return 0;
309 it.Next(); if (!it.More()) return 0;
310 //plus d un shape.
0797d9d3 311#ifdef OCCT_DEBUG
7fd59977 312 cout <<"WARNING IMPORTED"<<endl;
313#endif
314 return 1;
315}
316
317//=======================================================================
318//function : PrimitiveIdentification
319//purpose :
320//=======================================================================
321
322void TNaming_Identifier::PrimitiveIdentification (TNaming_Localizer& /*L*/,
323 const Handle(TNaming_NamedShape)& NS)
324{
325 myPrimitiveArgs.Append(NS);
326 myIsFeature = Standard_True;
327 myType = TNaming_MODIFUNTIL;
328 //Reconnaissance Shape Mort.
329 if (IsImported(NS)) {
330 myType = TNaming_CONSTSHAPE;
331 myIsFeature = Standard_False;
332 }
333 myDone = 1;
334}
335
336
337
338//=======================================================================
339//function : GeneratedIdentification
340//purpose : Finds generators of identifying shape <myShape> and keeps
341// : them in <myShapeArgs>
342//=======================================================================
343
344void TNaming_Identifier::GeneratedIdentification(TNaming_Localizer& /*Localizer*/,
345 const Handle(TNaming_NamedShape)& NS)
346{
347// TopoDS_Shape Gen; //szy 16.10.03
348 TopTools_ListOfShape aListOfGenerators;
349 TNaming_Localizer::FindGenerator (NS,myShape,aListOfGenerators);
350 myShapeArgs.Append(aListOfGenerators);
351 myNSContext = NS;
352 myType = TNaming_GENERATION;
353 myDone = 1;
354}
355
356//=======================================================================
357//function : Identification
358//purpose :
359//=======================================================================
360
361void TNaming_Identifier::Identification(TNaming_Localizer& Localizer,
362 const Handle(TNaming_NamedShape)& NS)
363{
364
365 TNaming_MapOfNamedShape Primitives;
366 TopTools_MapOfShape Shapes;
367
368 Localizer.Backward(NS,myShape,Primitives,Shapes);
369
370 if (Primitives.IsEmpty() && Shapes.IsEmpty()) {
371 myDone = 0;
372 return;
373 }
374 myType = TNaming_INTERSECTION;
375 TNaming_MapIteratorOfMapOfNamedShape itP(Primitives);
376 for (; itP.More(); itP.Next()) myPrimitiveArgs.Append(itP.Key());
377 TopTools_MapIteratorOfMapOfShape itS(Shapes);
378 for (; itS.More(); itS.Next()) myShapeArgs.Append(itS.Key());
379
380 if (myPrimitiveArgs.Extent() == 1 && myShapeArgs.IsEmpty()) {
381 myType = TNaming_MODIFUNTIL;
382 myIsFeature = Standard_True;
383 //Reconnaissance Shape Mort.
384 if (IsImported(myPrimitiveArgs.First())) {
385 myType = TNaming_CONSTSHAPE;
386 myIsFeature = Standard_False;
387 }
388 }
389 myDone = 1;
390}