1 // GEOM GEOMDS : implementation of Geometry component data structure and Geometry documents management
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeomDS_Commands.cxx
25 // Author : Yves FRICAUD/Lucien PIGNOLONI
30 #include "utilities.h"
31 #include "GEOMDS_Commands.ixx"
33 #include <TNaming_Builder.hxx>
34 #include <TNaming_NamedShape.hxx>
35 #include <TDataStd_Name.hxx>
36 #include <TDataStd_Integer.hxx>
37 #include <TDF_Reference.hxx>
38 #include <TNaming_Tool.hxx>
39 #include <TDF_ChildIterator.hxx>
42 //=======================================================================
43 //function : GEOMDS_Commands
45 //=======================================================================
46 GEOMDS_Commands::GEOMDS_Commands(const TDF_Label& Main)
52 //=======================================================================
53 // function : Generated()
55 //=======================================================================
56 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S,
57 const TCollection_ExtendedString& Name)
59 TDF_Label NewLab = myLab.NewChild();
60 TNaming_Builder B(NewLab);
62 TDataStd_Name::Set(NewLab,Name);
68 //=======================================================================
69 // function : Generated()
71 //=======================================================================
72 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S1,
73 const TopoDS_Shape& S2,
74 const TCollection_ExtendedString& Name)
76 TDF_Label NewLab = myLab.NewChild();
77 TNaming_Builder B(NewLab);
79 TDataStd_Name::Set(NewLab,Name);
85 //=======================================================================
86 // function : AddShape()
88 //=======================================================================
89 TDF_Label GEOMDS_Commands::AddShape(const TopoDS_Shape& S,
90 const TCollection_ExtendedString& Name)
92 TDF_Label NewLab = myLab.NewChild();
93 TNaming_Builder B(NewLab);
95 TDataStd_Name::Set(NewLab,Name);
100 //=======================================================================
101 // function : AddIndependentShape()
102 // purpose : SAME than AddShape() : will be renamed later
103 //=======================================================================
104 TDF_Label GEOMDS_Commands::AddIndependentShape(const TopoDS_Shape& S,
105 const TCollection_AsciiString& nameIOR)
107 TDF_Label NewLab = myLab.NewChild();
108 TNaming_Builder B(NewLab);
110 TDataStd_Name::Set(NewLab, nameIOR);
115 //=======================================================================
116 // function : AddDependentShape()
118 //=======================================================================
119 TDF_Label GEOMDS_Commands::AddDependentShape(const TopoDS_Shape& S,
120 const TCollection_AsciiString& nameIOR,
121 const TDF_Label& mainLab)
123 TDF_Label NewLab = myLab.NewChild();
124 TNaming_Builder B(NewLab);
126 TDataStd_Name::Set(NewLab, nameIOR);
127 /* NewLab has a reference attribute to mainLab (the main shape in fact) */
128 TDF_Reference::Set(NewLab, mainLab) ;
134 //=======================================================================
135 // function : AddConstructiveElement()
137 //=======================================================================
138 TDF_Label GEOMDS_Commands::AddConstructiveElement(const TopoDS_Shape& S,
139 const TCollection_ExtendedString& nameIOR,
140 const GEOMDS_ConstructiveType& aType)
142 TDF_Label NewLab = myLab.NewChild();
143 TNaming_Builder B(NewLab);
145 TDataStd_Name::Set(NewLab, nameIOR);
146 /* Add the Attribute Constructive Element coded with a TDataStd_Integer from an enum */
147 TDataStd_Integer::Set(NewLab, Standard_Integer(aType));
152 //=======================================================================
153 // function : AddIORNameAttribute()
154 // purpose : Add attribute TDataStd_Name to a label
155 // : this attribute represents the name/IOR of object
156 // : Return false if attribute exist before
157 //=======================================================================
158 Standard_Boolean GEOMDS_Commands::AddIORNameAttribute(const TDF_Label& aLabel,
159 const TCollection_ExtendedString& nameIOR)
161 if( this->HasIOR(aLabel) )
163 TDataStd_Name::Set(aLabel, nameIOR);
169 //=======================================================================
170 // function : IsConstructiveElement() 1/2
171 // purpose : Return true if 'aLabel' is a constructive element
172 //=======================================================================
173 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel)
175 Handle(TDataStd_Integer) anAttType ;
176 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType ) )
182 //=======================================================================
183 // function : IsConstructiveElement() 2/2
184 // purpose : Return true if 'aLabel' is a constructive element and return the
185 // : topology ' returnTopo' and type 'returnType'
186 //=======================================================================
187 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel,
188 TopoDS_Shape& returnTopo,
189 GEOMDS_ConstructiveType& returnType)
191 Handle(TDataStd_Integer) anAttType ;
192 Handle(TNaming_NamedShape) anAttTopo ;
194 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType) && aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
196 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
197 returnType = GEOMDS_ConstructiveType( anAttType->Get() ) ;
204 //=======================================================================
205 // function : GetShape()
206 // purpose : return true and 'returnTopo' if a topology is found on 'aLabel'
207 //=======================================================================
208 Standard_Boolean GEOMDS_Commands::GetShape(const TDF_Label& aLabel,
209 TopoDS_Shape& returnTopo)
211 Handle(TNaming_NamedShape) anAttTopo ;
212 if( aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
213 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
220 //=======================================================================
221 // function : IsDependentShape()
222 // purpose : return true if the shape in the label is dependant (a sub shape)
223 //=======================================================================
224 Standard_Boolean GEOMDS_Commands::IsDependentShape(const TDF_Label& aLabel)
226 Handle(TDF_Reference) anAttRef ;
227 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef))
234 //=======================================================================
235 // function : GetMainShapeLabel()
236 // purpose : return true if an attribute Reference is found for 'aLabel'
237 // : so 'returnMainLabel' is defined. 'aLabel' is supposed to be
238 // : a dependent object, otherwise return false.
239 //=======================================================================
240 Standard_Boolean GEOMDS_Commands::GetMainShapeLabel(const TDF_Label& aLabel,
241 TDF_Label& returnMainLabel)
243 Handle(TDF_Reference) anAttRef ;
244 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef)) {
245 returnMainLabel = anAttRef->Get() ;
252 //=======================================================================
253 // function : ClearAllIOR()
254 // purpose : Clear all IOR from aLabel usually the main label.
255 // : Useful before reconstruction after a load of a document.
256 // : IOR is the attribute often called 'name' or 'nameIOR'
257 //=======================================================================
258 Standard_Boolean GEOMDS_Commands::ClearAllIOR(const TDF_Label& aLabel)
260 TDF_ChildIterator it;
261 Handle(TDataStd_Name) anAttName ;
262 bool notTested = false ;
263 for( it.Initialize(aLabel, Standard_False); it.More(); it.Next() ) {
264 TDF_Label L = it.Value() ;
265 if( L.FindAttribute(TDataStd_Name::GetID(), anAttName) ) {
266 notTested = L.ForgetAttribute(TDataStd_Name::GetID()) ;
269 MESSAGE("in GEOMDS_Commands::ClearAllIOR : IOR CLEARED" )
275 //=======================================================================
276 // function : HasIOR()
277 // purpose : Return true is 'aLabel' has an attribute IOR (nameIOR)
278 //=======================================================================
279 Standard_Boolean GEOMDS_Commands::HasIOR(const TDF_Label& aLabel)
281 Handle(TDataStd_Name) anAttName ;
282 if( !aLabel.FindAttribute(TDataStd_Name::GetID(), anAttName) )
287 //=======================================================================
288 // function : ReturnNameIOR()
289 // purpose : Return true is 'aLabel' has an attribute IOR (nameIOR)
290 // : and define 'returnNameIOR'
291 //=======================================================================
292 Standard_Boolean GEOMDS_Commands::ReturnNameIOR(const TDF_Label& aLabel,
293 TCollection_ExtendedString& returnNameIOR)
295 Handle(TDataStd_Name) anAttName ;
296 if( !aLabel.FindAttribute(TDataStd_Name::GetID(), anAttName) )
299 returnNameIOR = anAttName->Get() ;