1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IGESData_IGESEntity.ixx>
15 #include <IGESData_NameEntity.hxx>
16 #include <IGESData_SingleParentEntity.hxx>
17 #include <Interface_InterfaceError.hxx>
18 #include <Standard_NoSuchObject.hxx>
21 #include <Interface_Macros.hxx>
22 #include <Standard_PCharacter.hxx>
25 #define ThisEntity Handle(IGESData_IGESEntity)::DownCast(This())
28 #define IGESFlagAssocs 131072
29 #define IGESFlagProps 262144
30 #define IGESFourStatus 65535
31 #define IGESStatusField 15
32 #define IGESShiftSubord 4
33 #define IGESShiftUse 8
34 #define IGESShiftHier 12
38 IGESData_IGESEntity::IGESData_IGESEntity ()
39 { Clear(); theRes1[0] = theRes2[0] = '\0'; }
41 void IGESData_IGESEntity::Clear ()
43 // Handle et DefSwitch
44 theStructure.Nullify();
45 theDefLineFont.SetVoid(); theLineFont.Nullify();
46 theDefColor.SetVoid(); theColor.Nullify();
47 theDefLevel = 0; theLevelList.Nullify();
48 theView.Nullify(); theTransf.Nullify(); theLabDisplay.Nullify();
49 theSubScriptN = 0; theShortLabel.Nullify();
51 // Autres Valeurs, Listes
52 theType = theForm = 0;
53 theStatusNum = theLWeightNum = 0;
55 // theRes1[0] = theRes2[0] = '\0';
56 theProps.Clear(); theAssocs.Clear();
60 // #########################################################################
61 // .... Definition IGES : Directory Entry ....
63 IGESData_IGESType IGESData_IGESEntity::IGESType () const
64 { return IGESData_IGESType(theType,theForm); }
66 Standard_Integer IGESData_IGESEntity::TypeNumber () const
69 Standard_Integer IGESData_IGESEntity::FormNumber () const
73 Handle(IGESData_IGESEntity) IGESData_IGESEntity::DirFieldEntity
74 (const Standard_Integer num) const
76 Handle(IGESData_IGESEntity) ent;
77 if (num == 3) ent = theStructure;
78 if (num == 4) ent = theLineFont;
79 if (num == 5) ent = theLevelList;
80 if (num == 6) ent = theView;
81 if (num == 7) ent = theTransf;
82 if (num == 8) ent = theLabDisplay;
83 if (num == 13) ent = theColor;
87 Standard_Boolean IGESData_IGESEntity::HasStructure () const
88 { return (!theStructure.IsNull()); }
90 Handle(IGESData_IGESEntity) IGESData_IGESEntity::Structure () const
91 { return theStructure; }
93 IGESData_DefType IGESData_IGESEntity::DefLineFont () const
94 { return theDefLineFont.DefType(); }
96 Standard_Integer IGESData_IGESEntity::RankLineFont () const
97 { return theDefLineFont.Value(); }
99 Handle(IGESData_LineFontEntity) IGESData_IGESEntity::LineFont () const
100 { return GetCasted(IGESData_LineFontEntity,theLineFont); }
102 IGESData_DefList IGESData_IGESEntity::DefLevel () const
104 if (theDefLevel > 0) return IGESData_DefOne;
105 if (theDefLevel < 0) return IGESData_DefSeveral;
106 return IGESData_DefNone;
109 Standard_Integer IGESData_IGESEntity::Level () const
110 { return theDefLevel; }
112 Handle(IGESData_LevelListEntity) IGESData_IGESEntity::LevelList () const
113 { return GetCasted(IGESData_LevelListEntity,theLevelList); }
116 IGESData_DefList IGESData_IGESEntity::DefView () const
118 if (View().IsNull()) return IGESData_DefNone;
119 if (View()->IsSingle()) return IGESData_DefOne;
120 else return IGESData_DefSeveral;
123 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::View () const
124 { return GetCasted(IGESData_ViewKindEntity,theView); }
126 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::SingleView () const
128 Handle(IGESData_ViewKindEntity) nulvue;
129 if (DefView() != IGESData_DefOne) return nulvue;
133 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::ViewList () const
135 Handle(IGESData_ViewKindEntity) nulvue;
136 if (DefView() != IGESData_DefSeveral) return nulvue;
141 Standard_Boolean IGESData_IGESEntity::HasTransf () const
142 { return (!theTransf.IsNull()); }
144 Handle(IGESData_TransfEntity) IGESData_IGESEntity::Transf () const
145 { return GetCasted(IGESData_TransfEntity,theTransf); }
148 Standard_Boolean IGESData_IGESEntity::HasLabelDisplay () const
149 { return (!theLabDisplay.IsNull()); }
151 Handle(IGESData_LabelDisplayEntity) IGESData_IGESEntity::LabelDisplay
153 { return GetCasted(IGESData_LabelDisplayEntity,theLabDisplay); }
155 // Status : un Integer pour BlankStatus,SubrodinateStatus,USeFlag,HierarchySt.
156 // Decoupage : 4 bits chacun (BlankStatus tout a droite, etc)
158 Standard_Integer IGESData_IGESEntity::BlankStatus () const
159 { return (theStatusNum & IGESStatusField); }
161 Standard_Integer IGESData_IGESEntity::SubordinateStatus () const
162 { return ((theStatusNum >> IGESShiftSubord) & IGESStatusField); }
164 Standard_Integer IGESData_IGESEntity::UseFlag () const
165 { return ((theStatusNum >> IGESShiftUse) & IGESStatusField); }
167 Standard_Integer IGESData_IGESEntity::HierarchyStatus () const
168 { return ((theStatusNum >> IGESShiftHier) & IGESStatusField); }
170 Standard_Integer IGESData_IGESEntity::LineWeightNumber () const
171 { return theLWeightNum; }
173 Standard_Real IGESData_IGESEntity::LineWeight () const
174 { return theLWeightVal; }
177 IGESData_DefType IGESData_IGESEntity::DefColor () const
178 { return theDefColor.DefType(); }
180 Standard_Integer IGESData_IGESEntity::RankColor () const
181 { return theDefColor.Value(); }
183 Handle(IGESData_ColorEntity) IGESData_IGESEntity::Color () const
184 { return GetCasted(IGESData_ColorEntity,theColor); }
187 //=======================================================================
188 //function : CResValues
190 //=======================================================================
191 Standard_Boolean IGESData_IGESEntity::CResValues (const Standard_CString res1,
192 const Standard_CString res2) const
194 Standard_Boolean res = Standard_False;
195 Standard_PCharacter pres1, pres2;
197 pres1=(Standard_PCharacter)res1;
198 pres2=(Standard_PCharacter)res2;
200 for (Standard_Integer i = 0; i < 8; i ++) {
201 pres1[i] = theRes1[i];
202 pres2[i] = theRes2[i];
203 if (theRes1[i] > ' ' || theRes2[i] > ' ') {
213 Standard_Boolean IGESData_IGESEntity::HasShortLabel () const
214 { return (!theShortLabel.IsNull()); }
216 Handle(TCollection_HAsciiString) IGESData_IGESEntity::ShortLabel () const
217 { return theShortLabel; }
219 Standard_Boolean IGESData_IGESEntity::HasSubScriptNumber () const
220 { return (theSubScriptN >= 0); } // =0 nul mais defini, <0 absent
222 Standard_Integer IGESData_IGESEntity::SubScriptNumber () const
224 if (theSubScriptN < 0) return 0;
225 return theSubScriptN;
228 // .... (Re)Initialisation du Directory ....
230 void IGESData_IGESEntity::InitTypeAndForm
231 (const Standard_Integer typenum, const Standard_Integer formnum)
232 { theType = typenum; theForm = formnum; }
234 void IGESData_IGESEntity::InitDirFieldEntity
235 (const Standard_Integer num, const Handle(IGESData_IGESEntity)& ent)
237 if (num == 3) theStructure = ent;
238 if (num == 4) theLineFont = ent;
239 if (num == 5) theLevelList = ent;
240 if (num == 6) theView = ent;
241 if (num == 7) theTransf = ent;
242 if (num == 8) theLabDisplay = ent;
243 if (num == 13) theColor = ent;
246 void IGESData_IGESEntity::InitTransf
247 (const Handle(IGESData_TransfEntity)& ent)
250 void IGESData_IGESEntity::InitView
251 (const Handle(IGESData_ViewKindEntity)& ent)
254 void IGESData_IGESEntity::InitLineFont
255 (const Handle(IGESData_LineFontEntity)& ent, const Standard_Integer rank)
256 { theDefLineFont.SetRank((ent.IsNull() ? rank : -1)); theLineFont = ent; }
258 void IGESData_IGESEntity::InitLevel
259 (const Handle(IGESData_LevelListEntity)& ent, const Standard_Integer val)
260 { theLevelList = ent; theDefLevel = (ent.IsNull() ? val : -1); }
262 void IGESData_IGESEntity::InitColor
263 (const Handle(IGESData_ColorEntity)& ent, const Standard_Integer rank)
264 { theDefColor.SetRank((ent.IsNull() ? rank : -1)); theColor = ent; }
266 void IGESData_IGESEntity::InitStatus
267 (const Standard_Integer blank, const Standard_Integer subordinate,
268 const Standard_Integer useflag, const Standard_Integer hierarchy)
270 theStatusNum = (theStatusNum & (!IGESFourStatus));
271 theStatusNum += (blank & IGESStatusField) |
272 ((subordinate & IGESStatusField) << IGESShiftSubord) |
273 ((useflag & IGESStatusField) << IGESShiftUse) |
274 ((hierarchy & IGESStatusField) << IGESShiftHier);
277 void IGESData_IGESEntity::SetLabel
278 (const Handle(TCollection_HAsciiString)& label, const Standard_Integer sub)
279 { theShortLabel = label; theSubScriptN = sub; }
281 void IGESData_IGESEntity::InitMisc
282 (const Handle(IGESData_IGESEntity)& str,
283 const Handle(IGESData_LabelDisplayEntity)& lab,
284 const Standard_Integer weightnum)
286 theStructure = str; theLabDisplay = lab;
287 if (theLWeightNum != 0) theLWeightVal *= (weightnum/theLWeightNum);
288 else if (weightnum == 0) theLWeightVal = 0;
289 theLWeightNum = weightnum;
292 // .... Notions derivees importantes ....
295 // SingleParent : ici on ne traite que l Associativity SingleParent
296 // Pour considerer le partage implicite, il faut remonter au Modele ...
298 Standard_Boolean IGESData_IGESEntity::HasOneParent () const
300 return (NbTypedProperties(STANDARD_TYPE(IGESData_SingleParentEntity)) == 1);
303 Handle(IGESData_IGESEntity) IGESData_IGESEntity::UniqueParent () const
305 if (NbTypedProperties(STANDARD_TYPE(IGESData_SingleParentEntity)) != 1)
306 Interface_InterfaceError::Raise ("IGESEntity : UniqueParent");
308 DeclareAndCast(IGESData_SingleParentEntity,PP,
309 TypedProperty(STANDARD_TYPE(IGESData_SingleParentEntity)));
310 return PP->SingleParent();
312 return this; // ne rime a rien (cf exception) mais calme le compilateur
316 gp_GTrsf IGESData_IGESEntity::Location () const
318 //szv#4:S4163:12Mar99 unreachcble eliminated
319 //if (!HasTransf()) return gp_GTrsf(); // Identite
320 //else return Transf()->Value(); // c-a-d Compoound
321 if (!HasTransf()) return gp_GTrsf(); // Identite
322 Handle(IGESData_TransfEntity) trsf = Transf();
323 return (trsf.IsNull())? gp_GTrsf() : trsf->Value();
326 gp_GTrsf IGESData_IGESEntity::VectorLocation () const
328 if (!HasTransf()) return gp_GTrsf(); // Identite
329 // Prendre Location et anuler TranslationPart
330 gp_GTrsf loca = Transf()->Value(); // c-a-d Compoound
331 loca.SetTranslationPart (gp_XYZ(0.,0.,0.));
335 gp_GTrsf IGESData_IGESEntity::CompoundLocation () const
337 gp_GTrsf loca = Location();
338 if (!HasOneParent()) return loca;
339 gp_GTrsf locp = UniqueParent()->CompoundLocation();
340 loca.PreMultiply(locp);
345 Standard_Boolean IGESData_IGESEntity::HasName () const
347 if (HasShortLabel()) return Standard_True;
348 return (NbTypedProperties(STANDARD_TYPE(IGESData_NameEntity)) == 1);
351 Handle(TCollection_HAsciiString) IGESData_IGESEntity::NameValue () const
353 Handle(TCollection_HAsciiString) nom; // au depart vide
354 // Question : concatene-t-on le SubScript ? Oui, forme label(subscript)
355 Standard_Integer nbname = NbTypedProperties(STANDARD_TYPE(IGESData_NameEntity));
357 if (!HasShortLabel()) return nom;
358 if (theSubScriptN < 0) return theShortLabel;
360 sprintf (lenom,"%s(%d)",theShortLabel->ToCString(),theSubScriptN);
361 nom = new TCollection_HAsciiString (lenom);
363 else if (nbname > 0) {
364 DeclareAndCast(IGESData_NameEntity,name,
365 TypedProperty(STANDARD_TYPE(IGESData_NameEntity), 1));
373 // .... Listes d'infos Optionnelles (Assocs,Props) ....
375 Standard_Boolean IGESData_IGESEntity::ArePresentAssociativities () const
377 if (!theAssocs.IsEmpty()) return Standard_True;
378 return (theStatusNum & IGESFlagAssocs);
381 Standard_Integer IGESData_IGESEntity::NbAssociativities () const
383 if (theAssocs.IsEmpty()) return 0;
384 return theAssocs.NbEntities();
387 Interface_EntityIterator IGESData_IGESEntity::Associativities () const
389 Interface_EntityIterator iter;
390 theAssocs.FillIterator(iter);
394 Standard_Integer IGESData_IGESEntity::NbTypedAssociativities
395 (const Handle(Standard_Type)& atype) const
396 { return theAssocs.NbTypedEntities(atype); }
398 Handle(IGESData_IGESEntity) IGESData_IGESEntity::TypedAssociativity
399 (const Handle(Standard_Type)& atype) const
400 { return GetCasted(IGESData_IGESEntity,theAssocs.TypedEntity(atype)); }
402 void IGESData_IGESEntity::AddAssociativity
403 (const Handle(IGESData_IGESEntity)& ent)
404 { theAssocs.Append(ent); }
406 void IGESData_IGESEntity::RemoveAssociativity
407 (const Handle(IGESData_IGESEntity)& ent)
408 { theAssocs.Remove(ent); }
410 void IGESData_IGESEntity::LoadAssociativities
411 (const Interface_EntityList& list)
412 { theAssocs = list; theStatusNum = (theStatusNum | IGESFlagAssocs); }
414 void IGESData_IGESEntity::ClearAssociativities ()
415 { theAssocs.Clear(); }
417 void IGESData_IGESEntity::Associate
418 (const Handle(IGESData_IGESEntity)& ent) const
419 { if (!ent.IsNull()) ent->AddAssociativity(ThisEntity); }
421 void IGESData_IGESEntity::Dissociate
422 (const Handle(IGESData_IGESEntity)& ent) const
423 { if (!ent.IsNull()) ent->RemoveAssociativity(ThisEntity); }
426 Standard_Boolean IGESData_IGESEntity::ArePresentProperties () const
428 if (!theProps.IsEmpty()) return Standard_True;
429 return (theStatusNum & IGESFlagProps);
432 Standard_Integer IGESData_IGESEntity::NbProperties () const
434 if (theProps.IsEmpty()) return 0;
435 return theProps.NbEntities();
438 Interface_EntityIterator IGESData_IGESEntity::Properties () const
440 Interface_EntityIterator iter;
441 theProps.FillIterator(iter);
445 Standard_Integer IGESData_IGESEntity::NbTypedProperties
446 (const Handle(Standard_Type)& atype) const
447 { return theProps.NbTypedEntities(atype); }
449 Handle(IGESData_IGESEntity) IGESData_IGESEntity::TypedProperty
450 (const Handle(Standard_Type)& atype, const Standard_Integer anum) const
451 { return GetCasted(IGESData_IGESEntity,theProps.TypedEntity(atype, anum)); }
453 void IGESData_IGESEntity::AddProperty
454 (const Handle(IGESData_IGESEntity)& ent)
455 { theProps.Append(ent); }
457 void IGESData_IGESEntity::RemoveProperty
458 (const Handle(IGESData_IGESEntity)& ent)
459 { theProps.Remove(ent); }
461 void IGESData_IGESEntity::LoadProperties
462 (const Interface_EntityList& list)
463 { theProps = list; theStatusNum = (theStatusNum | IGESFlagProps); }
465 void IGESData_IGESEntity::ClearProperties ()
466 { theProps.Clear(); }
468 // .... Actions liees au Transfert ....
470 void IGESData_IGESEntity::SetLineWeight
471 (const Standard_Real defw, const Standard_Real maxw,
472 const Standard_Integer gradw)
474 if (theLWeightNum == 0) theLWeightVal = defw;
475 else if (gradw == 1) theLWeightVal = maxw*theLWeightNum;
476 else theLWeightVal = (maxw*theLWeightNum)/gradw;