1 // Created on: 1997-03-04
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TNaming_Identifier.ixx>
18 #include <TNaming_Localizer.hxx>
19 #include <TNaming_NamedShape.hxx>
20 #include <TNaming_UsedShapes.hxx>
21 #include <TNaming_Iterator.hxx>
22 #include <TNaming_Tool.hxx>
23 #include <TNaming_MapOfNamedShape.hxx>
24 #include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
25 #include <TopTools_MapOfShape.hxx>
26 #include <TopTools_MapIteratorOfMapOfShape.hxx>
27 #include <TDF_ChildIterator.hxx>
29 //#define MDTV_DEB_IDF
31 #include <TCollection_AsciiString.hxx>
32 #include <TDF_Tool.hxx>
33 #include <BRepTools.hxx>
35 //unreferenced function, commented
36 /*static void ModDbgTools_Write(const TopoDS_Shape& shape,
37 const Standard_CString filename)
41 save << "DBRep_DrawableShape" << endl << endl;
42 if(!shape.IsNull()) BRepTools::Write(shape, save);
46 static void ModDbgTools_WriteCurrentShape(const Handle(TNaming_NamedShape) & NS)
48 TCollection_AsciiString entry;
49 TDF_Tool::Entry(NS->Label(), entry);
52 TopoDS_Shape Sh = TNaming_Tool::CurrentShape (NS);
54 TCollection_AsciiString Entry = entry.Cat("_Cur.brep");
55 ModDbgTools_Write(Sh, Entry.ToCString());
58 cout << "ModDbgTools::Write>>> TopoDS_Shape IS NULL on Entry = "<< entry << endl;
61 cout << "ModDbgTools::Write>>> CurrentShape of TNaming_NamedShape IS NULL on Entry = "<< entry << endl;
65 //=======================================================================
66 //function : TNaming_Identifier
68 //=======================================================================
70 TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
71 const TopoDS_Shape& S,
72 const TopoDS_Shape& Context,
73 const Standard_Boolean /*OneOnly*/)
74 :myTDFAcces(LabAcces), myShape(S),
75 myDone(Standard_False),myIsFeature(Standard_False)
80 //=======================================================================
81 //function : TNaming_Identifier
83 //=======================================================================
85 TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
86 const TopoDS_Shape& S,
87 const Handle(TNaming_NamedShape)& ContextNS,
88 const Standard_Boolean /*OneOnly*/)
89 :myTDFAcces(LabAcces), myShape(S),
90 myDone(Standard_False),myIsFeature(Standard_False)
92 const TopoDS_Shape& aContext = TNaming_Tool::GetShape (ContextNS);
96 //=======================================================================
99 //=======================================================================
100 void TNaming_Identifier::Init(const TopoDS_Shape& Context)
102 Handle(TNaming_UsedShapes) US;
103 myTDFAcces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
105 TNaming_Localizer Localizer;
106 Localizer.Init (US,myTDFAcces.Transaction());
108 Handle(TNaming_NamedShape) NS;
109 NS = TNaming_Tool::NamedShape(myShape, myTDFAcces);
111 AncestorIdentification(Localizer, Context);
114 #ifdef OCCT_DEBUG_IDF
115 TCollection_AsciiString entry;
116 TDF_Tool::Entry(NS->Label(), entry);
117 cout << "Identifier:: (S) Label = " << entry <<endl;
119 //-------------------------------------
120 // S est New dans un NamedShape
121 //-------------------------------------
122 TNaming_Evolution Evol = NS->Evolution();
123 if (Evol == TNaming_PRIMITIVE) {
124 PrimitiveIdentification(Localizer,NS);
126 else if (Evol == TNaming_GENERATED) {
127 GeneratedIdentification(Localizer,NS);
130 Identification(Localizer,NS);
134 //=======================================================================
137 //=======================================================================
139 TNaming_NameType TNaming_Identifier::Type() const
144 //=======================================================================
147 //=======================================================================
149 Standard_Boolean TNaming_Identifier::IsDone() const
155 //=======================================================================
156 //function : IsFeature
158 //=======================================================================
160 Standard_Boolean TNaming_Identifier::IsFeature()
166 //=======================================================================
169 //=======================================================================
171 Handle(TNaming_NamedShape) TNaming_Identifier::Feature() const
173 return myPrimitiveArgs.First();
177 //=======================================================================
178 //function : InitArgs
180 //=======================================================================
182 void TNaming_Identifier::InitArgs()
187 //=======================================================================
188 //function : MoreArgs
190 //=======================================================================
192 Standard_Boolean TNaming_Identifier::MoreArgs() const
194 return (!myPrimitiveArgs.IsEmpty() || !myShapeArgs.IsEmpty());
197 //=======================================================================
198 //function : ArgIsFeature
200 //=======================================================================
202 Standard_Boolean TNaming_Identifier::ArgIsFeature() const
204 return (!myPrimitiveArgs.IsEmpty());
207 //=======================================================================
210 //=======================================================================
212 void TNaming_Identifier::NextArg()
214 if (!myPrimitiveArgs.IsEmpty()) myPrimitiveArgs.RemoveFirst();
215 else if (!myShapeArgs .IsEmpty()) myShapeArgs .RemoveFirst();
218 //=======================================================================
219 //function : FeatureArg
221 //=======================================================================
223 Handle(TNaming_NamedShape) TNaming_Identifier::FeatureArg()
225 return myPrimitiveArgs.First();
229 //=======================================================================
230 //function : ShapeArg
232 //=======================================================================
234 TopoDS_Shape TNaming_Identifier::ShapeArg()
236 return myShapeArgs.First();
240 //=======================================================================
241 //function : ShapeContext
243 //=======================================================================
245 TopoDS_Shape TNaming_Identifier::ShapeContext() const
247 const TopoDS_Shape& S = myShapeArgs.First();
249 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(S,myTDFAcces);
250 TNaming_Localizer::FindShapeContext (NS, S, SC); // szy ==> added par. S
255 //=======================================================================
256 //function : Handle(TNaming_NamedShape)
258 //=======================================================================
260 Handle(TNaming_NamedShape) TNaming_Identifier::NamedShapeOfGeneration() const
265 //=======================================================================
266 //function : AncestorIdentification
268 //=======================================================================
270 void TNaming_Identifier::AncestorIdentification(TNaming_Localizer& Localizer,
271 const TopoDS_Shape& Context)
273 TopTools_MapOfShape AncInFeature;
274 if (Context.IsNull()) {
275 myType = TNaming_UNKNOWN;
279 Localizer.FindFeaturesInAncestors (myShape, Context, AncInFeature);
281 if (AncInFeature.IsEmpty()) {
285 myType = TNaming_INTERSECTION;
286 TopTools_MapIteratorOfMapOfShape itS(AncInFeature);
287 for (; itS.More(); itS.Next()) myShapeArgs.Append(itS.Key());
291 //=======================================================================
292 //function : Imported
294 //=======================================================================
296 Standard_Boolean IsImported(const Handle(TNaming_NamedShape)& NS)
298 TDF_Label Lab = NS->Label();
299 TDF_Label Father = Lab.Father();
300 for (TDF_ChildIterator cit(Father); cit.More(); cit.Next()) {
301 if (cit.Value() != Lab) return 0;
304 TNaming_Iterator it(NS);
305 if (!it.More()) return 0;
306 it.Next(); if (!it.More()) return 0;
309 cout <<"WARNING IMPORTED"<<endl;
314 //=======================================================================
315 //function : PrimitiveIdentification
317 //=======================================================================
319 void TNaming_Identifier::PrimitiveIdentification (TNaming_Localizer& /*L*/,
320 const Handle(TNaming_NamedShape)& NS)
322 myPrimitiveArgs.Append(NS);
323 myIsFeature = Standard_True;
324 myType = TNaming_MODIFUNTIL;
325 //Reconnaissance Shape Mort.
326 if (IsImported(NS)) {
327 myType = TNaming_CONSTSHAPE;
328 myIsFeature = Standard_False;
335 //=======================================================================
336 //function : GeneratedIdentification
337 //purpose : Finds generators of identifying shape <myShape> and keeps
338 // : them in <myShapeArgs>
339 //=======================================================================
341 void TNaming_Identifier::GeneratedIdentification(TNaming_Localizer& /*Localizer*/,
342 const Handle(TNaming_NamedShape)& NS)
344 // TopoDS_Shape Gen; //szy 16.10.03
345 TopTools_ListOfShape aListOfGenerators;
346 TNaming_Localizer::FindGenerator (NS,myShape,aListOfGenerators);
347 myShapeArgs.Append(aListOfGenerators);
349 myType = TNaming_GENERATION;
353 //=======================================================================
354 //function : Identification
356 //=======================================================================
358 void TNaming_Identifier::Identification(TNaming_Localizer& Localizer,
359 const Handle(TNaming_NamedShape)& NS)
362 TNaming_MapOfNamedShape Primitives;
363 TopTools_MapOfShape Shapes;
365 Localizer.Backward(NS,myShape,Primitives,Shapes);
367 if (Primitives.IsEmpty() && Shapes.IsEmpty()) {
371 myType = TNaming_INTERSECTION;
372 TNaming_MapIteratorOfMapOfNamedShape itP(Primitives);
373 for (; itP.More(); itP.Next()) myPrimitiveArgs.Append(itP.Key());
374 TopTools_MapIteratorOfMapOfShape itS(Shapes);
375 for (; itS.More(); itS.Next()) myShapeArgs.Append(itS.Key());
377 if (myPrimitiveArgs.Extent() == 1 && myShapeArgs.IsEmpty()) {
378 myType = TNaming_MODIFUNTIL;
379 myIsFeature = Standard_True;
380 //Reconnaissance Shape Mort.
381 if (IsImported(myPrimitiveArgs.First())) {
382 myType = TNaming_CONSTSHAPE;
383 myIsFeature = Standard_False;