1 // Created on: 2009-05-05
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <DNaming_SelectionDriver.hxx>
18 #include <ModelDefinitions.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDataStd_Integer.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_LabelMap.hxx>
23 #include <TFunction_Function.hxx>
24 #include <TFunction_Logbook.hxx>
25 #include <TNaming_Builder.hxx>
26 #include <TNaming_NamedShape.hxx>
27 #include <TNaming_Selector.hxx>
28 #include <TNaming_Tool.hxx>
30 #include <TopoDS_Shape.hxx>
34 #include <TDF_Tool.hxx>
35 #include <TDF_MapIteratorOfLabelMap.hxx>
37 //=======================================================================
38 //function : DNaming_SelectionDriver
39 //purpose : Constructor
40 //=======================================================================
41 DNaming_SelectionDriver::DNaming_SelectionDriver()
44 //=======================================================================
46 //purpose : Validates labels of a function in <theLog>.
47 //=======================================================================
48 void DNaming_SelectionDriver::Validate(TFunction_Logbook& ) const
51 //=======================================================================
52 //function : MustExecute
53 //purpose : Analyse in <theLog> if the loaded function must be
54 // executed (i.e.arguments are modified) or not.
55 //=======================================================================
56 Standard_Boolean DNaming_SelectionDriver::MustExecute(const TFunction_Logbook& ) const {
61 #include <BRepTools.hxx>
62 static void Write(const TopoDS_Shape& shape,
63 const Standard_CString filename)
67 save << "DBRep_DrawableShape" << endl << endl;
68 if(!shape.IsNull()) BRepTools::Write(shape, save);
72 //=======================================================================
74 //purpose : Execute the function and push in <theLog> the impacted
75 // labels (see method SetImpacted).
76 //=======================================================================
77 #include <TNaming_ListOfNamedShape.hxx>
78 #include <TDF_AttributeMap.hxx>
79 #include <TDF_IDFilter.hxx>
80 #include <TDF_Tool.hxx>
81 #include <TDF_MapIteratorOfAttributeMap.hxx>
82 #include <TCollection_AsciiString.hxx>
83 #include <TDF_ChildIterator.hxx>
85 Standard_Integer DNaming_SelectionDriver::Execute(TFunction_Logbook& theLog) const
87 Handle(TFunction_Function) aFunction;
88 Label().FindAttribute(TFunction_Function::GetID(),aFunction);
89 if(aFunction.IsNull()) return -1;
92 TDF_Label aRLabel = RESPOSITION(aFunction);
93 if(aRLabel.IsNull()) return -1;
95 Standard_Boolean aIsWire = Standard_False;
96 TopAbs_ShapeEnum aPrevShapeType = TopAbs_SHAPE;
97 Handle(TNaming_NamedShape) aNShape;
98 if(aRLabel.FindAttribute(TNaming_NamedShape::GetID(),aNShape)) {
99 if(!aNShape.IsNull() && !aNShape->IsEmpty()) {
100 aPrevShapeType = aNShape->Get().ShapeType();
101 if (aPrevShapeType == TopAbs_WIRE) aIsWire = Standard_True;
105 TNaming_Selector aSelector(aRLabel);
108 aMap = theLog.ChangeValid();
110 cout <<"#E_DNaming_SelectionDriver:: Valid Label Map:"<<endl;
111 TDF_MapIteratorOfLabelMap anItr(aMap);
112 for (; anItr.More(); anItr.Next()) {
113 const TDF_Label& aLabel = anItr.Key();
114 TCollection_AsciiString anEntry;
115 TDF_Tool::Entry(aLabel, anEntry);
116 cout << "\tLabel = " << anEntry << endl;
120 // TDF_IDFilter aFilterForReferers;
121 // aFilterForReferers.Keep(TNaming_NamedShape::GetID());
122 // TDF_IDFilter aFilterForReferences;
123 // aFilterForReferences.Keep(TNaming_NamedShape::GetID());
124 // TDF_LabelMap aMap1;
125 // TDF_Tool::OutReferences(aLabel, /*aFilterForReferers, aFilterForReferences, */outRefs);
128 if(aSelector.Solve(aMap)) {
129 theLog.SetValid(aRLabel);
130 Handle(TNaming_NamedShape) aNS;
131 if(!aRLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
132 cout <<"%%%WARNING: DNaming_SelectionDriver::NamedShape is not found"<<endl;
136 cout << "%%%WARNING: DNaming_SelectionDriver::NamedShape is NULL" <<endl;
139 cout << "%%%WARNING: DNaming_SelectionDriver::NamedShape is EMPTY on Label = ";
140 aNS->Label().EntryDump(cout); cout << endl;
144 Write(aNS->Get(), "Selection_Result.brep");
145 Handle(TopoDS_TShape) aTS = aNS->Get().TShape();
146 cout << "TShape = " << (Standard_Address)aTS <<endl;
148 if(aIsWire && aNS->Get().ShapeType()== TopAbs_COMPOUND) {
149 TopoDS_Shape aWireShape;
150 TNaming_Tool::FindShape(aMap, aMap, aNS, aWireShape);
151 TNaming_Builder aBuilder(aRLabel);
152 aBuilder.Select(aWireShape, aWireShape);
153 aFunction->SetFailure(DONE);
155 if(aPrevShapeType == aNS->Get().ShapeType()) {
156 aFunction->SetFailure(DONE);
159 cout <<"%%%WARNING: DNaming_SelectionDriver::Execute: The Shape after solving changed type = "<<aNS->Get().ShapeType()<< endl;
161 aFunction->SetFailure(DONE);
167 aFunction->SetFailure(NOTDONE);
168 cout << "%%%WARNING: DNaming_SelectionDriver::Execute: Selection is Not solved !!!" << endl;