1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMDS : implementation of Geometry component data structure and Geometry documents management
23 // File : GeomDS_Commands.cxx
24 // Author : Yves FRICAUD/Lucien PIGNOLONI
29 #include "utilities.h"
30 #include "GEOMDS_Commands.ixx"
32 #include <TNaming_Builder.hxx>
33 #include <TNaming_NamedShape.hxx>
34 #include <TDataStd_Name.hxx>
35 #include <TDataStd_Integer.hxx>
36 #include <TDF_Reference.hxx>
37 #include <TNaming_Tool.hxx>
38 #include <TDF_ChildIterator.hxx>
41 //=======================================================================
42 //function : GEOMDS_Commands
44 //=======================================================================
45 GEOMDS_Commands::GEOMDS_Commands(const TDF_Label& Main)
51 //=======================================================================
52 // function : Generated()
54 //=======================================================================
55 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S,
56 const TCollection_ExtendedString& Name)
58 TDF_Label NewLab = myLab.NewChild();
59 TNaming_Builder B(NewLab);
61 TDataStd_Name::Set(NewLab,Name);
67 //=======================================================================
68 // function : Generated()
70 //=======================================================================
71 TDF_Label GEOMDS_Commands::Generated(const TopoDS_Shape& S1,
72 const TopoDS_Shape& S2,
73 const TCollection_ExtendedString& Name)
75 TDF_Label NewLab = myLab.NewChild();
76 TNaming_Builder B(NewLab);
78 TDataStd_Name::Set(NewLab,Name);
84 //=======================================================================
85 // function : AddShape()
87 //=======================================================================
88 TDF_Label GEOMDS_Commands::AddShape(const TopoDS_Shape& S,
89 const TCollection_ExtendedString& Name)
91 TDF_Label NewLab = myLab.NewChild();
92 TNaming_Builder B(NewLab);
94 TDataStd_Name::Set(NewLab,Name);
99 //=======================================================================
100 // function : AddIndependentShape()
101 // purpose : SAME than AddShape() : will be renamed later
102 //=======================================================================
103 TDF_Label GEOMDS_Commands::AddIndependentShape(const TopoDS_Shape& S,
104 const TCollection_AsciiString& nameIOR)
106 TDF_Label NewLab = myLab.NewChild();
107 TNaming_Builder B(NewLab);
109 TDataStd_Name::Set(NewLab, nameIOR);
114 //=======================================================================
115 // function : AddDependentShape()
117 //=======================================================================
118 TDF_Label GEOMDS_Commands::AddDependentShape(const TopoDS_Shape& S,
119 const TCollection_AsciiString& nameIOR,
120 const TDF_Label& mainLab)
122 TDF_Label NewLab = myLab.NewChild();
123 TNaming_Builder B(NewLab);
125 TDataStd_Name::Set(NewLab, nameIOR);
126 /* NewLab has a reference attribute to mainLab (the main shape in fact) */
127 TDF_Reference::Set(NewLab, mainLab) ;
133 //=======================================================================
134 // function : AddConstructiveElement()
136 //=======================================================================
137 TDF_Label GEOMDS_Commands::AddConstructiveElement(const TopoDS_Shape& S,
138 const TCollection_ExtendedString& nameIOR,
139 const GEOMDS_ConstructiveType& aType)
141 TDF_Label NewLab = myLab.NewChild();
142 TNaming_Builder B(NewLab);
144 TDataStd_Name::Set(NewLab, nameIOR);
145 /* Add the Attribute Constructive Element coded with a TDataStd_Integer from an enum */
146 TDataStd_Integer::Set(NewLab, Standard_Integer(aType));
151 //=======================================================================
152 // function : AddIORNameAttribute()
153 // purpose : Add attribute TDataStd_Name to a label
154 // : this attribute represents the name/IOR of object
155 // : Return false if attribute exist before
156 //=======================================================================
157 Standard_Boolean GEOMDS_Commands::AddIORNameAttribute(const TDF_Label& aLabel,
158 const TCollection_ExtendedString& nameIOR)
160 if( this->HasIOR(aLabel) )
162 TDataStd_Name::Set(aLabel, nameIOR);
168 //=======================================================================
169 // function : IsConstructiveElement() 1/2
170 // purpose : Return true if 'aLabel' is a constructive element
171 //=======================================================================
172 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel)
174 Handle(TDataStd_Integer) anAttType ;
175 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType ) )
181 //=======================================================================
182 // function : IsConstructiveElement() 2/2
183 // purpose : Return true if 'aLabel' is a constructive element and return the
184 // : topology ' returnTopo' and type 'returnType'
185 //=======================================================================
186 Standard_Boolean GEOMDS_Commands::IsConstructiveElement(const TDF_Label& aLabel,
187 TopoDS_Shape& returnTopo,
188 GEOMDS_ConstructiveType& returnType)
190 Handle(TDataStd_Integer) anAttType ;
191 Handle(TNaming_NamedShape) anAttTopo ;
193 if( aLabel.FindAttribute(TDataStd_Integer::GetID(), anAttType) && aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
195 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
196 returnType = GEOMDS_ConstructiveType( anAttType->Get() ) ;
203 //=======================================================================
204 // function : GetShape()
205 // purpose : return true and 'returnTopo' if a topology is found on 'aLabel'
206 //=======================================================================
207 Standard_Boolean GEOMDS_Commands::GetShape(const TDF_Label& aLabel,
208 TopoDS_Shape& returnTopo)
210 Handle(TNaming_NamedShape) anAttTopo ;
211 if( aLabel.FindAttribute(TNaming_NamedShape::GetID(), anAttTopo)) {
212 returnTopo = TNaming_Tool::GetShape(anAttTopo) ;
219 //=======================================================================
220 // function : IsDependentShape()
221 // purpose : return true if the shape in the label is dependant (a sub shape)
222 //=======================================================================
223 Standard_Boolean GEOMDS_Commands::IsDependentShape(const TDF_Label& aLabel)
225 Handle(TDF_Reference) anAttRef ;
226 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef))
233 //=======================================================================
234 // function : GetMainShapeLabel()
235 // purpose : return true if an attribute Reference is found for 'aLabel'
236 // : so 'returnMainLabel' is defined. 'aLabel' is supposed to be
237 // : a dependent object, otherwise return false.
238 //=======================================================================
239 Standard_Boolean GEOMDS_Commands::GetMainShapeLabel(const TDF_Label& aLabel,
240 TDF_Label& returnMainLabel)
242 Handle(TDF_Reference) anAttRef ;
243 if( aLabel.FindAttribute(TDF_Reference::GetID(), anAttRef)) {
244 returnMainLabel = anAttRef->Get() ;
251 //=======================================================================
252 // function : ClearAllIOR()
253 // purpose : Clear all IOR from aLabel usually the main label.
254 // : Useful before reconstruction after a load of a document.
255 // : IOR is the attribute often called 'name' or 'nameIOR'
256 //=======================================================================
257 Standard_Boolean GEOMDS_Commands::ClearAllIOR(const TDF_Label& aLabel)
259 TDF_ChildIterator it;
260 Handle(TDataStd_Name) anAttName ;
261 bool notTested = false ;
262 for( it.Initialize(aLabel, Standard_False); it.More(); it.Next() ) {
263 TDF_Label L = it.Value() ;
264 if( L.FindAttribute(TDataStd_Name::GetID(), anAttName) ) {
265 notTested = L.ForgetAttribute(TDataStd_Name::GetID()) ;
267 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() ;