2 // File : GeomDS_Commands.cxx
4 // Author : Yves FRICAUD/Lucien PIGNOLONI
7 // Copyright : OPEN CASCADE
10 #include "utilities.h"
11 #include "GEOMDS_Commands.ixx"
13 #include <TNaming_Builder.hxx>
14 #include <TNaming_NamedShape.hxx>
15 #include <TDataStd_Name.hxx>
16 #include <TDataStd_Integer.hxx>
17 #include <TDF_Reference.hxx>
18 #include <TNaming_Tool.hxx>
19 #include <TDF_ChildIterator.hxx>
22 //=======================================================================
23 //function : GEOMDS_Commands
25 //=======================================================================
26 GEOMDS_Commands::GEOMDS_Commands(const TDF_Label& Main)
32 //=======================================================================
33 // function : Generated()
35 //=======================================================================
36 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S,
37 const TCollection_ExtendedString& Name)
39 TDF_Label NewLab = myLab.NewChild();
40 TNaming_Builder B(NewLab);
42 TDataStd_Name::Set(NewLab,Name);
48 //=======================================================================
49 // function : Generated()
51 //=======================================================================
52 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S1,
53 const TopoDS_Shape& S2,
54 const TCollection_ExtendedString& Name)
56 TDF_Label NewLab = myLab.NewChild();
57 TNaming_Builder B(NewLab);
59 TDataStd_Name::Set(NewLab,Name);
65 //=======================================================================
66 // function : AddShape()
68 //=======================================================================
69 TDF_Label GEOMDS_Commands::AddShape(const TopoDS_Shape& S,
70 const TCollection_ExtendedString& Name)
72 TDF_Label NewLab = myLab.NewChild();
73 TNaming_Builder B(NewLab);
75 TDataStd_Name::Set(NewLab,Name);
80 //=======================================================================
81 // function : AddIndependentShape()
82 // purpose : SAME than AddShape() : will be renamed later
83 //=======================================================================
84 TDF_Label GEOMDS_Commands::AddIndependentShape(const TopoDS_Shape& S,
85 const TCollection_AsciiString& nameIOR)
87 TDF_Label NewLab = myLab.NewChild();
88 TNaming_Builder B(NewLab);
90 TDataStd_Name::Set(NewLab, nameIOR);
95 //=======================================================================
96 // function : AddDependentShape()
98 //=======================================================================
99 TDF_Label GEOMDS_Commands::AddDependentShape(const TopoDS_Shape& S,
100 const TCollection_AsciiString& nameIOR,
101 const TDF_Label& mainLab)
103 TDF_Label NewLab = myLab.NewChild();
104 TNaming_Builder B(NewLab);
106 TDataStd_Name::Set(NewLab, nameIOR);
107 /* NewLab has a reference attribute to mainLab (the main shape in fact) */
108 TDF_Reference::Set(NewLab, mainLab) ;
114 //=======================================================================
115 // function : AddConstructiveElement()
117 //=======================================================================
118 TDF_Label GEOMDS_Commands::AddConstructiveElement(const TopoDS_Shape& S,
119 const TCollection_ExtendedString& nameIOR,
120 const GEOMDS_ConstructiveType& aType)
122 TDF_Label NewLab = myLab.NewChild();
123 TNaming_Builder B(NewLab);
125 TDataStd_Name::Set(NewLab, nameIOR);
126 /* Add the Attribute Constructive Element coded with a TDataStd_Integer from an enum */
127 TDataStd_Integer::Set(NewLab, Standard_Integer(aType));
132 //=======================================================================
133 // function : AddIORNameAttribute()
134 // purpose : Add attribute TDataStd_Name to a label
135 // : this attribute represents the name/IOR of object
136 // : Return false if attribute exist before
137 //=======================================================================
138 Standard_Boolean GEOMDS_Commands::AddIORNameAttribute(const TDF_Label& aLabel,
139 const TCollection_ExtendedString& nameIOR)
141 if( this->HasIOR(aLabel) )
143 TDataStd_Name::Set(aLabel, nameIOR);
149 //=======================================================================
150 // function : IsConstructiveElement() 1/2
151 // purpose : Return true if 'aLabel' is a constructive element
152 //=======================================================================
153 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel)
155 Handle(TDataStd_Integer) anAttType ;
156 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType ) )
162 //=======================================================================
163 // function : IsConstructiveElement() 2/2
164 // purpose : Return true if 'aLabel' is a constructive element and return the
165 // : topology ' returnTopo' and type 'returnType'
166 //=======================================================================
167 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel,
168 TopoDS_Shape& returnTopo,
169 GEOMDS_ConstructiveType& returnType)
171 Handle(TDataStd_Integer) anAttType ;
172 Handle(TNaming_NamedShape) anAttTopo ;
174 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType) && aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
176 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
177 returnType = GEOMDS_ConstructiveType( anAttType->Get() ) ;
184 //=======================================================================
185 // function : GetShape()
186 // purpose : return true and 'returnTopo' if a topology is found on 'aLabel'
187 //=======================================================================
188 Standard_Boolean GEOMDS_Commands::GetShape(const TDF_Label& aLabel,
189 TopoDS_Shape& returnTopo)
191 Handle(TNaming_NamedShape) anAttTopo ;
192 if( aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
193 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
200 //=======================================================================
201 // function : IsDependentShape()
202 // purpose : return true if the shape in the label is dependant (a sub shape)
203 //=======================================================================
204 Standard_Boolean GEOMDS_Commands::IsDependentShape(const TDF_Label& aLabel)
206 Handle(TDF_Reference) anAttRef ;
207 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef))
214 //=======================================================================
215 // function : GetMainShapeLabel()
216 // purpose : return true if an attribute Reference is found for 'aLabel'
217 // : so 'returnMainLabel' is defined. 'aLabel' is supposed to be
218 // : a dependent object, otherwise return false.
219 //=======================================================================
220 Standard_Boolean GEOMDS_Commands::GetMainShapeLabel(const TDF_Label& aLabel,
221 TDF_Label& returnMainLabel)
223 Handle(TDF_Reference) anAttRef ;
224 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef)) {
225 returnMainLabel = anAttRef->Get() ;
232 //=======================================================================
233 // function : ClearAllIOR()
234 // purpose : Clear all IOR from aLabel usually the main label.
235 // : Useful before reconstruction after a load of a document.
236 // : IOR is the attribute often called 'name' or 'nameIOR'
237 //=======================================================================
238 Standard_Boolean GEOMDS_Commands::ClearAllIOR(const TDF_Label& aLabel)
240 TDF_ChildIterator it;
241 Handle(TDataStd_Name) anAttName ;
242 bool notTested = false ;
243 for( it.Initialize(aLabel, Standard_False); it.More(); it.Next() ) {
244 TDF_Label L = it.Value() ;
245 if( L.FindAttribute(TDataStd_Name::GetID(), anAttName) ) {
246 notTested = L.ForgetAttribute(TDataStd_Name::GetID()) ;
249 MESSAGE("in GEOMDS_Commands::ClearAllIOR : IOR CLEARED" )
255 //=======================================================================
256 // function : HasIOR()
257 // purpose : Return true is 'aLabel' has an attribute IOR (nameIOR)
258 //=======================================================================
259 Standard_Boolean GEOMDS_Commands::HasIOR(const TDF_Label& aLabel)
261 Handle(TDataStd_Name) anAttName ;
262 if( !aLabel.FindAttribute(TDataStd_Name::GetID(), anAttName) )
267 //=======================================================================
268 // function : ReturnNameIOR()
269 // purpose : Return true is 'aLabel' has an attribute IOR (nameIOR)
270 // : and define 'returnNameIOR'
271 //=======================================================================
272 Standard_Boolean GEOMDS_Commands::ReturnNameIOR(const TDF_Label& aLabel,
273 TCollection_ExtendedString& returnNameIOR)
275 Handle(TDataStd_Name) anAttName ;
276 if( !aLabel.FindAttribute(TDataStd_Name::GetID(), anAttName) )
279 returnNameIOR = anAttName->Get() ;