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.
15 #include <gp_GTrsf.hxx>
16 #include <IGESData_ColorEntity.hxx>
17 #include <IGESData_DirChecker.hxx>
18 #include <IGESData_GeneralModule.hxx>
19 #include <IGESData_IGESEntity.hxx>
20 #include <IGESData_IGESReaderTool.hxx>
21 #include <IGESData_IGESType.hxx>
22 #include <IGESData_LabelDisplayEntity.hxx>
23 #include <IGESData_LevelListEntity.hxx>
24 #include <IGESData_LineFontEntity.hxx>
25 #include <IGESData_NameEntity.hxx>
26 #include <IGESData_ReadWriteModule.hxx>
27 #include <IGESData_SingleParentEntity.hxx>
28 #include <IGESData_TransfEntity.hxx>
29 #include <IGESData_ViewKindEntity.hxx>
30 #include <Interface_EntityIterator.hxx>
31 #include <Interface_EntityList.hxx>
32 #include <Interface_InterfaceError.hxx>
33 #include <Interface_Macros.hxx>
34 #include <Standard_NoSuchObject.hxx>
35 #include <Standard_PCharacter.hxx>
36 #include <Standard_Type.hxx>
37 #include <TCollection_HAsciiString.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(IGESData_IGESEntity,Standard_Transient)
42 #define ThisEntity Handle(IGESData_IGESEntity)::DownCast(This())
46 static const Standard_Integer IGESFlagAssocs = 131072;
47 static const Standard_Integer IGESFlagProps = 262144;
48 static const Standard_Integer IGESFourStatus = 65535;
49 static const Standard_Integer IGESStatusField = 15;
50 static const Standard_Integer IGESShiftSubord = 4;
51 static const Standard_Integer IGESShiftUse = 8;
52 static const Standard_Integer IGESShiftHier = 12;
55 //=======================================================================
56 //function : IGESData_IGESEntity
57 //purpose : Default constructor.
58 //=======================================================================
59 IGESData_IGESEntity::IGESData_IGESEntity()
68 theRes1[0] = theRes2[0] = '\0';
71 //=======================================================================
74 //=======================================================================
75 void IGESData_IGESEntity::Clear ()
77 // Handle et DefSwitch
78 theStructure.Nullify();
79 theDefLineFont.SetVoid(); theLineFont.Nullify();
80 theDefColor.SetVoid(); theColor.Nullify();
81 theDefLevel = 0; theLevelList.Nullify();
82 theView.Nullify(); theTransf.Nullify(); theLabDisplay.Nullify();
83 theSubScriptN = 0; theShortLabel.Nullify();
85 // Autres Valeurs, Listes
86 theType = theForm = 0;
87 theStatusNum = theLWeightNum = 0;
89 // theRes1[0] = theRes2[0] = '\0';
90 theProps.Clear(); theAssocs.Clear();
94 // #########################################################################
95 // .... Definition IGES : Directory Entry ....
97 IGESData_IGESType IGESData_IGESEntity::IGESType () const
98 { return IGESData_IGESType(theType,theForm); }
100 Standard_Integer IGESData_IGESEntity::TypeNumber () const
103 Standard_Integer IGESData_IGESEntity::FormNumber () const
107 Handle(IGESData_IGESEntity) IGESData_IGESEntity::DirFieldEntity
108 (const Standard_Integer num) const
110 Handle(IGESData_IGESEntity) ent;
111 if (num == 3) ent = theStructure;
112 if (num == 4) ent = theLineFont;
113 if (num == 5) ent = theLevelList;
114 if (num == 6) ent = theView;
115 if (num == 7) ent = theTransf;
116 if (num == 8) ent = theLabDisplay;
117 if (num == 13) ent = theColor;
121 Standard_Boolean IGESData_IGESEntity::HasStructure () const
122 { return (!theStructure.IsNull()); }
124 Handle(IGESData_IGESEntity) IGESData_IGESEntity::Structure () const
125 { return theStructure; }
127 IGESData_DefType IGESData_IGESEntity::DefLineFont () const
128 { return theDefLineFont.DefType(); }
130 Standard_Integer IGESData_IGESEntity::RankLineFont () const
131 { return theDefLineFont.Value(); }
133 Handle(IGESData_LineFontEntity) IGESData_IGESEntity::LineFont () const
134 { return GetCasted(IGESData_LineFontEntity,theLineFont); }
136 IGESData_DefList IGESData_IGESEntity::DefLevel () const
138 if (theDefLevel > 0) return IGESData_DefOne;
139 if (theDefLevel < 0) return IGESData_DefSeveral;
140 return IGESData_DefNone;
143 Standard_Integer IGESData_IGESEntity::Level () const
144 { return theDefLevel; }
146 Handle(IGESData_LevelListEntity) IGESData_IGESEntity::LevelList () const
147 { return GetCasted(IGESData_LevelListEntity,theLevelList); }
150 IGESData_DefList IGESData_IGESEntity::DefView () const
152 if (View().IsNull()) return IGESData_DefNone;
153 if (View()->IsSingle()) return IGESData_DefOne;
154 else return IGESData_DefSeveral;
157 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::View () const
158 { return GetCasted(IGESData_ViewKindEntity,theView); }
160 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::SingleView () const
162 Handle(IGESData_ViewKindEntity) nulvue;
163 if (DefView() != IGESData_DefOne) return nulvue;
167 Handle(IGESData_ViewKindEntity) IGESData_IGESEntity::ViewList () const
169 Handle(IGESData_ViewKindEntity) nulvue;
170 if (DefView() != IGESData_DefSeveral) return nulvue;
175 Standard_Boolean IGESData_IGESEntity::HasTransf () const
176 { return (!theTransf.IsNull()); }
178 Handle(IGESData_TransfEntity) IGESData_IGESEntity::Transf () const
179 { return GetCasted(IGESData_TransfEntity,theTransf); }
182 Standard_Boolean IGESData_IGESEntity::HasLabelDisplay () const
183 { return (!theLabDisplay.IsNull()); }
185 Handle(IGESData_LabelDisplayEntity) IGESData_IGESEntity::LabelDisplay
187 { return GetCasted(IGESData_LabelDisplayEntity,theLabDisplay); }
189 // Status : un Integer pour BlankStatus,SubrodinateStatus,USeFlag,HierarchySt.
190 // Decoupage : 4 bits chacun (BlankStatus tout a droite, etc)
192 Standard_Integer IGESData_IGESEntity::BlankStatus () const
193 { return (theStatusNum & IGESStatusField); }
195 Standard_Integer IGESData_IGESEntity::SubordinateStatus () const
196 { return ((theStatusNum >> IGESShiftSubord) & IGESStatusField); }
198 Standard_Integer IGESData_IGESEntity::UseFlag () const
199 { return ((theStatusNum >> IGESShiftUse) & IGESStatusField); }
201 Standard_Integer IGESData_IGESEntity::HierarchyStatus () const
202 { return ((theStatusNum >> IGESShiftHier) & IGESStatusField); }
204 Standard_Integer IGESData_IGESEntity::LineWeightNumber () const
205 { return theLWeightNum; }
207 Standard_Real IGESData_IGESEntity::LineWeight () const
208 { return theLWeightVal; }
211 IGESData_DefType IGESData_IGESEntity::DefColor () const
212 { return theDefColor.DefType(); }
214 Standard_Integer IGESData_IGESEntity::RankColor () const
215 { return theDefColor.Value(); }
217 Handle(IGESData_ColorEntity) IGESData_IGESEntity::Color () const
218 { return GetCasted(IGESData_ColorEntity,theColor); }
221 //=======================================================================
222 //function : CResValues
224 //=======================================================================
225 Standard_Boolean IGESData_IGESEntity::CResValues (const Standard_CString res1,
226 const Standard_CString res2) const
228 Standard_Boolean res = Standard_False;
229 Standard_PCharacter pres1, pres2;
231 pres1=(Standard_PCharacter)res1;
232 pres2=(Standard_PCharacter)res2;
234 for (Standard_Integer i = 0; i < 8; i ++) {
235 pres1[i] = theRes1[i];
236 pres2[i] = theRes2[i];
237 if (theRes1[i] > ' ' || theRes2[i] > ' ') {
247 Standard_Boolean IGESData_IGESEntity::HasShortLabel () const
248 { return (!theShortLabel.IsNull()); }
250 Handle(TCollection_HAsciiString) IGESData_IGESEntity::ShortLabel () const
251 { return theShortLabel; }
253 Standard_Boolean IGESData_IGESEntity::HasSubScriptNumber () const
254 { return (theSubScriptN >= 0); } // =0 nul mais defini, <0 absent
256 Standard_Integer IGESData_IGESEntity::SubScriptNumber () const
258 if (theSubScriptN < 0) return 0;
259 return theSubScriptN;
262 // .... (Re)Initialisation du Directory ....
264 void IGESData_IGESEntity::InitTypeAndForm
265 (const Standard_Integer typenum, const Standard_Integer formnum)
266 { theType = typenum; theForm = formnum; }
268 void IGESData_IGESEntity::InitDirFieldEntity
269 (const Standard_Integer num, const Handle(IGESData_IGESEntity)& ent)
271 if (num == 3) theStructure = ent;
272 if (num == 4) theLineFont = ent;
273 if (num == 5) theLevelList = ent;
274 if (num == 6) theView = ent;
275 if (num == 7) theTransf = ent;
276 if (num == 8) theLabDisplay = ent;
277 if (num == 13) theColor = ent;
280 void IGESData_IGESEntity::InitTransf
281 (const Handle(IGESData_TransfEntity)& ent)
284 void IGESData_IGESEntity::InitView
285 (const Handle(IGESData_ViewKindEntity)& ent)
288 void IGESData_IGESEntity::InitLineFont
289 (const Handle(IGESData_LineFontEntity)& ent, const Standard_Integer rank)
290 { theDefLineFont.SetRank((ent.IsNull() ? rank : -1)); theLineFont = ent; }
292 void IGESData_IGESEntity::InitLevel
293 (const Handle(IGESData_LevelListEntity)& ent, const Standard_Integer val)
294 { theLevelList = ent; theDefLevel = (ent.IsNull() ? val : -1); }
296 void IGESData_IGESEntity::InitColor
297 (const Handle(IGESData_ColorEntity)& ent, const Standard_Integer rank)
298 { theDefColor.SetRank((ent.IsNull() ? rank : -1)); theColor = ent; }
300 void IGESData_IGESEntity::InitStatus
301 (const Standard_Integer blank, const Standard_Integer subordinate,
302 const Standard_Integer useflag, const Standard_Integer hierarchy)
304 theStatusNum = (theStatusNum & (!IGESFourStatus));
305 theStatusNum += (blank & IGESStatusField) |
306 ((subordinate & IGESStatusField) << IGESShiftSubord) |
307 ((useflag & IGESStatusField) << IGESShiftUse) |
308 ((hierarchy & IGESStatusField) << IGESShiftHier);
311 void IGESData_IGESEntity::SetLabel
312 (const Handle(TCollection_HAsciiString)& label, const Standard_Integer sub)
313 { theShortLabel = label; theSubScriptN = sub; }
315 void IGESData_IGESEntity::InitMisc
316 (const Handle(IGESData_IGESEntity)& str,
317 const Handle(IGESData_LabelDisplayEntity)& lab,
318 const Standard_Integer weightnum)
320 theStructure = str; theLabDisplay = lab;
321 if (theLWeightNum != 0) theLWeightVal *= (weightnum/theLWeightNum);
322 else if (weightnum == 0) theLWeightVal = 0;
323 theLWeightNum = weightnum;
326 // .... Notions derivees importantes ....
329 // SingleParent : ici on ne traite que l Associativity SingleParent
330 // Pour considerer le partage implicite, il faut remonter au Modele ...
332 Standard_Boolean IGESData_IGESEntity::HasOneParent () const
334 return (NbTypedProperties(STANDARD_TYPE(IGESData_SingleParentEntity)) == 1);
337 Handle(IGESData_IGESEntity) IGESData_IGESEntity::UniqueParent () const
339 if (NbTypedProperties(STANDARD_TYPE(IGESData_SingleParentEntity)) != 1)
340 throw Interface_InterfaceError("IGESEntity : UniqueParent");
342 DeclareAndCast(IGESData_SingleParentEntity,PP,
343 TypedProperty(STANDARD_TYPE(IGESData_SingleParentEntity)));
344 return PP->SingleParent();
349 gp_GTrsf IGESData_IGESEntity::Location () const
351 //szv#4:S4163:12Mar99 unreachcble eliminated
352 //if (!HasTransf()) return gp_GTrsf(); // Identite
353 //else return Transf()->Value(); // c-a-d Compoound
354 if (!HasTransf()) return gp_GTrsf(); // Identite
355 Handle(IGESData_TransfEntity) trsf = Transf();
356 return (trsf.IsNull())? gp_GTrsf() : trsf->Value();
359 gp_GTrsf IGESData_IGESEntity::VectorLocation () const
361 if (!HasTransf()) return gp_GTrsf(); // Identite
362 // Prendre Location et anuler TranslationPart
363 gp_GTrsf loca = Transf()->Value(); // c-a-d Compoound
364 loca.SetTranslationPart (gp_XYZ(0.,0.,0.));
368 gp_GTrsf IGESData_IGESEntity::CompoundLocation () const
370 gp_GTrsf loca = Location();
371 if (!HasOneParent()) return loca;
372 gp_GTrsf locp = UniqueParent()->CompoundLocation();
373 loca.PreMultiply(locp);
378 Standard_Boolean IGESData_IGESEntity::HasName () const
380 if (HasShortLabel()) return Standard_True;
381 return (NbTypedProperties(STANDARD_TYPE(IGESData_NameEntity)) == 1);
384 Handle(TCollection_HAsciiString) IGESData_IGESEntity::NameValue () const
386 Handle(TCollection_HAsciiString) nom; // au depart vide
387 // Question : concatene-t-on le SubScript ? Oui, forme label(subscript)
388 Standard_Integer nbname = NbTypedProperties(STANDARD_TYPE(IGESData_NameEntity));
390 if (!HasShortLabel()) return nom;
391 if (theSubScriptN < 0) return theShortLabel;
393 sprintf (lenom,"%s(%d)",theShortLabel->ToCString(),theSubScriptN);
394 nom = new TCollection_HAsciiString (lenom);
396 else if (nbname > 0) {
397 DeclareAndCast(IGESData_NameEntity,name,
398 TypedProperty(STANDARD_TYPE(IGESData_NameEntity), 1));
406 // .... Listes d'infos Optionnelles (Assocs,Props) ....
408 Standard_Boolean IGESData_IGESEntity::ArePresentAssociativities () const
410 if (!theAssocs.IsEmpty()) return Standard_True;
411 return (theStatusNum & IGESFlagAssocs) != 0;
414 Standard_Integer IGESData_IGESEntity::NbAssociativities () const
416 if (theAssocs.IsEmpty()) return 0;
417 return theAssocs.NbEntities();
420 Interface_EntityIterator IGESData_IGESEntity::Associativities () const
422 Interface_EntityIterator iter;
423 theAssocs.FillIterator(iter);
427 Standard_Integer IGESData_IGESEntity::NbTypedAssociativities
428 (const Handle(Standard_Type)& atype) const
429 { return theAssocs.NbTypedEntities(atype); }
431 Handle(IGESData_IGESEntity) IGESData_IGESEntity::TypedAssociativity
432 (const Handle(Standard_Type)& atype) const
433 { return GetCasted(IGESData_IGESEntity,theAssocs.TypedEntity(atype)); }
435 void IGESData_IGESEntity::AddAssociativity
436 (const Handle(IGESData_IGESEntity)& ent)
437 { theAssocs.Append(ent); }
439 void IGESData_IGESEntity::RemoveAssociativity
440 (const Handle(IGESData_IGESEntity)& ent)
441 { theAssocs.Remove(ent); }
443 void IGESData_IGESEntity::LoadAssociativities
444 (const Interface_EntityList& list)
445 { theAssocs = list; theStatusNum = (theStatusNum | IGESFlagAssocs); }
447 void IGESData_IGESEntity::ClearAssociativities ()
448 { theAssocs.Clear(); }
450 void IGESData_IGESEntity::Associate
451 (const Handle(IGESData_IGESEntity)& ent) const
452 { if (!ent.IsNull()) ent->AddAssociativity(ThisEntity); }
454 void IGESData_IGESEntity::Dissociate
455 (const Handle(IGESData_IGESEntity)& ent) const
456 { if (!ent.IsNull()) ent->RemoveAssociativity(ThisEntity); }
459 Standard_Boolean IGESData_IGESEntity::ArePresentProperties () const
461 if (!theProps.IsEmpty()) return Standard_True;
462 return (theStatusNum & IGESFlagProps) != 0;
465 Standard_Integer IGESData_IGESEntity::NbProperties () const
467 if (theProps.IsEmpty()) return 0;
468 return theProps.NbEntities();
471 Interface_EntityIterator IGESData_IGESEntity::Properties () const
473 Interface_EntityIterator iter;
474 theProps.FillIterator(iter);
478 Standard_Integer IGESData_IGESEntity::NbTypedProperties
479 (const Handle(Standard_Type)& atype) const
480 { return theProps.NbTypedEntities(atype); }
482 Handle(IGESData_IGESEntity) IGESData_IGESEntity::TypedProperty
483 (const Handle(Standard_Type)& atype, const Standard_Integer anum) const
484 { return GetCasted(IGESData_IGESEntity,theProps.TypedEntity(atype, anum)); }
486 void IGESData_IGESEntity::AddProperty
487 (const Handle(IGESData_IGESEntity)& ent)
488 { theProps.Append(ent); }
490 void IGESData_IGESEntity::RemoveProperty
491 (const Handle(IGESData_IGESEntity)& ent)
492 { theProps.Remove(ent); }
494 void IGESData_IGESEntity::LoadProperties
495 (const Interface_EntityList& list)
496 { theProps = list; theStatusNum = (theStatusNum | IGESFlagProps); }
498 void IGESData_IGESEntity::ClearProperties ()
499 { theProps.Clear(); }
501 // .... Actions liees au Transfert ....
503 void IGESData_IGESEntity::SetLineWeight
504 (const Standard_Real defw, const Standard_Real maxw,
505 const Standard_Integer gradw)
507 if (theLWeightNum == 0) theLWeightVal = defw;
508 else if (gradw == 1) theLWeightVal = maxw*theLWeightNum;
509 else theLWeightVal = (maxw*theLWeightNum)/gradw;