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.
18 #include <TDF_ChildIterator.hxx>
19 #include <TDF_Label.hxx>
20 #include <TNaming_Identifier.hxx>
21 #include <TNaming_Iterator.hxx>
22 #include <TNaming_Localizer.hxx>
23 #include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
24 #include <TNaming_MapOfNamedShape.hxx>
25 #include <TNaming_NamedShape.hxx>
26 #include <TNaming_Tool.hxx>
27 #include <TNaming_UsedShapes.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopTools_MapIteratorOfMapOfShape.hxx>
30 #include <TopTools_MapOfShape.hxx>
32 //#define MDTV_DEB_IDF
34 #include <TCollection_AsciiString.hxx>
35 #include <TDF_Tool.hxx>
36 #include <BRepTools.hxx>
38 //unreferenced function, commented
39 /*static void ModDbgTools_Write(const TopoDS_Shape& shape,
40 const Standard_CString filename)
44 save << "DBRep_DrawableShape" << std::endl << std::endl;
45 if(!shape.IsNull()) BRepTools::Write(shape, save);
49 static void ModDbgTools_WriteCurrentShape(const Handle(TNaming_NamedShape) & NS)
51 TCollection_AsciiString entry;
52 TDF_Tool::Entry(NS->Label(), entry);
55 TopoDS_Shape Sh = TNaming_Tool::CurrentShape (NS);
57 TCollection_AsciiString Entry = entry.Cat("_Cur.brep");
58 ModDbgTools_Write(Sh, Entry.ToCString());
61 std::cout << "ModDbgTools::Write>>> TopoDS_Shape IS NULL on Entry = "<< entry << std::endl;
64 std::cout << "ModDbgTools::Write>>> CurrentShape of TNaming_NamedShape IS NULL on Entry = "<< entry << std::endl;
68 //=======================================================================
69 //function : TNaming_Identifier
71 //=======================================================================
73 TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
74 const TopoDS_Shape& S,
75 const TopoDS_Shape& Context,
76 const Standard_Boolean /*OneOnly*/)
77 :myTDFAcces(LabAcces), myShape(S),
78 myDone(Standard_False),myIsFeature(Standard_False)
83 //=======================================================================
84 //function : TNaming_Identifier
86 //=======================================================================
88 TNaming_Identifier::TNaming_Identifier(const TDF_Label& LabAcces,
89 const TopoDS_Shape& S,
90 const Handle(TNaming_NamedShape)& ContextNS,
91 const Standard_Boolean /*OneOnly*/)
92 :myTDFAcces(LabAcces), myShape(S),
93 myDone(Standard_False),myIsFeature(Standard_False)
95 const TopoDS_Shape& aContext = TNaming_Tool::GetShape (ContextNS);
99 //=======================================================================
102 //=======================================================================
103 void TNaming_Identifier::Init(const TopoDS_Shape& Context)
105 Handle(TNaming_UsedShapes) US;
106 myTDFAcces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
108 TNaming_Localizer Localizer;
109 Localizer.Init (US,myTDFAcces.Transaction());
111 Handle(TNaming_NamedShape) NS;
112 NS = TNaming_Tool::NamedShape(myShape, myTDFAcces);
114 AncestorIdentification(Localizer, Context);
117 #ifdef OCCT_DEBUG_IDF
118 TCollection_AsciiString entry;
119 TDF_Tool::Entry(NS->Label(), entry);
120 std::cout << "Identifier:: (S) Label = " << entry <<std::endl;
122 //-------------------------------------
123 // S est New dans un NamedShape
124 //-------------------------------------
125 TNaming_Evolution Evol = NS->Evolution();
126 if (Evol == TNaming_PRIMITIVE) {
127 PrimitiveIdentification(Localizer,NS);
129 else if (Evol == TNaming_GENERATED) {
130 GeneratedIdentification(Localizer,NS);
133 Identification(Localizer,NS);
137 //=======================================================================
140 //=======================================================================
142 TNaming_NameType TNaming_Identifier::Type() const
147 //=======================================================================
150 //=======================================================================
152 Standard_Boolean TNaming_Identifier::IsDone() const
158 //=======================================================================
159 //function : IsFeature
161 //=======================================================================
163 Standard_Boolean TNaming_Identifier::IsFeature()
169 //=======================================================================
172 //=======================================================================
174 Handle(TNaming_NamedShape) TNaming_Identifier::Feature() const
176 return myPrimitiveArgs.First();
180 //=======================================================================
181 //function : InitArgs
183 //=======================================================================
185 void TNaming_Identifier::InitArgs()
190 //=======================================================================
191 //function : MoreArgs
193 //=======================================================================
195 Standard_Boolean TNaming_Identifier::MoreArgs() const
197 return (!myPrimitiveArgs.IsEmpty() || !myShapeArgs.IsEmpty());
200 //=======================================================================
201 //function : ArgIsFeature
203 //=======================================================================
205 Standard_Boolean TNaming_Identifier::ArgIsFeature() const
207 return (!myPrimitiveArgs.IsEmpty());
210 //=======================================================================
213 //=======================================================================
215 void TNaming_Identifier::NextArg()
217 if (!myPrimitiveArgs.IsEmpty()) myPrimitiveArgs.RemoveFirst();
218 else if (!myShapeArgs .IsEmpty()) myShapeArgs .RemoveFirst();
221 //=======================================================================
222 //function : FeatureArg
224 //=======================================================================
226 Handle(TNaming_NamedShape) TNaming_Identifier::FeatureArg()
228 return myPrimitiveArgs.First();
232 //=======================================================================
233 //function : ShapeArg
235 //=======================================================================
237 TopoDS_Shape TNaming_Identifier::ShapeArg()
239 return myShapeArgs.First();
243 //=======================================================================
244 //function : ShapeContext
246 //=======================================================================
248 TopoDS_Shape TNaming_Identifier::ShapeContext() const
250 const TopoDS_Shape& S = myShapeArgs.First();
252 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(S,myTDFAcces);
253 TNaming_Localizer::FindShapeContext (NS, S, SC); // szy ==> added par. S
258 //=======================================================================
259 //function : Handle(TNaming_NamedShape)
261 //=======================================================================
263 Handle(TNaming_NamedShape) TNaming_Identifier::NamedShapeOfGeneration() const
268 //=======================================================================
269 //function : AncestorIdentification
271 //=======================================================================
273 void TNaming_Identifier::AncestorIdentification(TNaming_Localizer& Localizer,
274 const TopoDS_Shape& Context)
276 TopTools_MapOfShape AncInFeature;
277 if (Context.IsNull()) {
278 myType = TNaming_UNKNOWN;
282 Localizer.FindFeaturesInAncestors (myShape, Context, AncInFeature);
284 if (AncInFeature.IsEmpty()) {
288 myType = TNaming_INTERSECTION;
289 TopTools_MapIteratorOfMapOfShape itS(AncInFeature);
290 for (; itS.More(); itS.Next()) myShapeArgs.Append(itS.Key());
294 //=======================================================================
295 //function : Imported
297 //=======================================================================
299 Standard_Boolean IsImported(const Handle(TNaming_NamedShape)& NS)
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;
307 TNaming_Iterator it(NS);
308 if (!it.More()) return 0;
309 it.Next(); if (!it.More()) return 0;
312 std::cout <<"WARNING IMPORTED"<<std::endl;
317 //=======================================================================
318 //function : PrimitiveIdentification
320 //=======================================================================
322 void TNaming_Identifier::PrimitiveIdentification (TNaming_Localizer& /*L*/,
323 const Handle(TNaming_NamedShape)& NS)
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;
338 //=======================================================================
339 //function : GeneratedIdentification
340 //purpose : Finds generators of identifying shape <myShape> and keeps
341 // : them in <myShapeArgs>
342 //=======================================================================
344 void TNaming_Identifier::GeneratedIdentification(TNaming_Localizer& /*Localizer*/,
345 const Handle(TNaming_NamedShape)& NS)
347 // TopoDS_Shape Gen; //szy 16.10.03
348 TopTools_ListOfShape aListOfGenerators;
349 TNaming_Localizer::FindGenerator (NS,myShape,aListOfGenerators);
350 myShapeArgs.Append(aListOfGenerators);
352 myType = TNaming_GENERATION;
356 //=======================================================================
357 //function : Identification
359 //=======================================================================
361 void TNaming_Identifier::Identification(TNaming_Localizer& Localizer,
362 const Handle(TNaming_NamedShape)& NS)
365 TNaming_MapOfNamedShape Primitives;
366 TopTools_MapOfShape Shapes;
368 Localizer.Backward(NS,myShape,Primitives,Shapes);
370 if (Primitives.IsEmpty() && Shapes.IsEmpty()) {
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());
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;