0030451: Selection mode of TPrsStd_AISPresentation attribute is restricted to one...
[occt.git] / src / TDataXtd / TDataXtd_Presentation.cxx
CommitLineData
f47afe53 1// Created on: 2015-04-20
2// Created by: Alexander Zaikin
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2015 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <TDataXtd_Presentation.hxx>
18
19#include <TDF_DefaultDeltaOnRemoval.hxx>
20#include <TDF_DefaultDeltaOnModification.hxx>
21#include <TDF_DeltaOnAddition.hxx>
22#include <TDF_Tool.hxx>
23#include <TCollection_ExtendedString.hxx>
24
25IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Presentation,TDF_Attribute)
26
27//=======================================================================
28//function : TDataXtd_Presentation
29//purpose : Default constructor.
30//=======================================================================
31TDataXtd_Presentation::TDataXtd_Presentation()
32: myDriverGUID ("00000000-0000-0000-0000-000000000000"),
33 myColor (Quantity_NOC_WHITE),
34 myMaterialIndex (0),
35 myMode (0),
f47afe53 36 myTransparency (0.0),
37 myWidth (0.0),
38 myIsDisplayed (Standard_False),
39 myHasOwnColor (Standard_False),
40 myHasOwnMaterial (Standard_False),
41 myHasOwnTransparency (Standard_False),
42 myHasOwnWidth (Standard_False),
43 myHasOwnMode (Standard_False),
44 myHasOwnSelectionMode (Standard_False)
45{}
46
47
48//=======================================================================
49//function : Set
50//purpose :
51//=======================================================================
52Handle(TDataXtd_Presentation) TDataXtd_Presentation::Set (const TDF_Label& theLabel,
53 const Standard_GUID& theDriverId)
54{
55 Handle(TDataXtd_Presentation) aPresentation;
56
57 if ( !theLabel.FindAttribute(TDataXtd_Presentation::GetID(), aPresentation) )
58 {
59 aPresentation = new TDataXtd_Presentation();
60 theLabel.AddAttribute(aPresentation);
61 }
62
63 aPresentation->SetDriverGUID(theDriverId);
64 return aPresentation;
65}
66
67//=======================================================================
68//function : Unset
69//purpose :
70//=======================================================================
71void TDataXtd_Presentation::Unset(const TDF_Label& theLabel)
72{
73 Handle(TDataXtd_Presentation) aPresentation;
74 if (theLabel.FindAttribute(TDataXtd_Presentation::GetID(), aPresentation))
75 theLabel.ForgetAttribute(aPresentation);
76}
77
78
79//=======================================================================
80//function : GetID
81//purpose :
82//=======================================================================
83const Standard_GUID& TDataXtd_Presentation::GetID()
84{
85 static Standard_GUID TDataXtd_PresentationID("04fb4d00-5690-11d1-8940-080009dc3333");
86 return TDataXtd_PresentationID;
87}
88
89
90//=======================================================================
91//function : ID
92//purpose :
93//=======================================================================
94const Standard_GUID& TDataXtd_Presentation::ID() const
95{
96 return GetID();
97}
98
99
100//=======================================================================
101//function :GetDriverGUID
102//purpose :
103//=======================================================================
104Standard_GUID TDataXtd_Presentation::GetDriverGUID() const
105{
106 return myDriverGUID;
107}
108
109
110//=======================================================================
111//function :SetDriverGUID
112//purpose :
113//=======================================================================
114void TDataXtd_Presentation::SetDriverGUID(const Standard_GUID& theGUID)
115{
116 if ( myDriverGUID != theGUID )
117 {
118 Backup();
119 myDriverGUID = theGUID;
120 }
121}
122
123
124//=======================================================================
125//function : IsDisplayed
126//purpose :
127//=======================================================================
128Standard_Boolean TDataXtd_Presentation::IsDisplayed() const
129{
130 return myIsDisplayed;
131}
132
133
134//=======================================================================
135//function : HasOwnMaterial
136//purpose :
137//=======================================================================
138Standard_Boolean TDataXtd_Presentation::HasOwnMaterial() const
139{
140 return myHasOwnMaterial;
141}
142
143
144//=======================================================================
145//function : HasOwnTransparency
146//purpose :
147//=======================================================================
148Standard_Boolean TDataXtd_Presentation::HasOwnTransparency() const
149{
150 return myHasOwnTransparency;
151}
152
153
154//=======================================================================
155//function : HasOwnColor
156//purpose :
157//=======================================================================
158Standard_Boolean TDataXtd_Presentation::HasOwnColor() const
159{
160 return myHasOwnColor;
161}
162
163
164//=======================================================================
165//function : HasOwnWidth
166//purpose :
167//=======================================================================
168Standard_Boolean TDataXtd_Presentation::HasOwnWidth() const
169{
170 return myHasOwnWidth;
171}
172
173
174//=======================================================================
175//function : HasOwnMode
176//purpose :
177//=======================================================================
178Standard_Boolean TDataXtd_Presentation::HasOwnMode() const
179{
180 return myHasOwnMode;
181}
182
183
184//=======================================================================
185//function : HasOwnSelectionMode
186//purpose :
187//=======================================================================
188Standard_Boolean TDataXtd_Presentation::HasOwnSelectionMode() const
189{
190 return myHasOwnSelectionMode;
191}
192
193
194//=======================================================================
195//function : SetDisplayed
196//purpose :
197//=======================================================================
198void TDataXtd_Presentation::SetDisplayed(const Standard_Boolean theIsDisplayed)
199{
200 if (myIsDisplayed != theIsDisplayed)
201 {
202 Backup();
203 myIsDisplayed = theIsDisplayed;
204 }
205}
206
207
208//=======================================================================
209//function : SetMaterialIndex
210//purpose :
211//=======================================================================
212void TDataXtd_Presentation::SetMaterialIndex(const Standard_Integer theMaterialIndex)
213{
214 if (! myHasOwnMaterial || myMaterialIndex != theMaterialIndex)
215 {
216 Backup();
217 myMaterialIndex = theMaterialIndex;
218 myHasOwnMaterial = Standard_True;
219 }
220}
221
222
223//=======================================================================
224//function : SetTransparency
225//purpose :
226//=======================================================================
227void TDataXtd_Presentation::SetTransparency(const Standard_Real theValue)
228{
229 if (! myHasOwnTransparency || myTransparency != theValue)
230 {
231 Backup();
232 myTransparency = theValue;
233 myHasOwnTransparency = Standard_True;
234 }
235}
236
237
238//=======================================================================
239//function : SetColor
240//purpose :
241//=======================================================================
242void TDataXtd_Presentation::SetColor(const Quantity_NameOfColor theColor)
243{
244 if (! myHasOwnColor || myColor != theColor)
245 {
246 Backup();
247 myColor = theColor;
248 myHasOwnColor = Standard_True;
249 }
250}
251
252
253//=======================================================================
254//function : SetWidth
255//purpose :
256//=======================================================================
257void TDataXtd_Presentation::SetWidth(const Standard_Real theWidth)
258{
259 if (! myHasOwnWidth || myWidth != theWidth)
260 {
261 Backup();
262 myWidth = theWidth;
263 myHasOwnWidth = Standard_True;
264 }
265}
266
267
268//=======================================================================
269//function : SetMode
270//purpose :
271//=======================================================================
272void TDataXtd_Presentation::SetMode(const Standard_Integer theMode)
273{
274 if (! myHasOwnMode || myMode != theMode)
275 {
276 Backup();
277 myMode = theMode;
278 myHasOwnMode = Standard_True;
279 }
280}
281
a0d0f96a 282//=======================================================================
283//function : GetNbSelectionModes
284//purpose : Returns the number of selection modes of the attribute.
285// : It starts with 1 .. GetNbSelectionModes().
286//=======================================================================
287Standard_EXPORT Standard_Integer TDataXtd_Presentation::GetNbSelectionModes() const
288{
289 return mySelectionModes.Extent();
290}
f47afe53 291
292//=======================================================================
293//function : SetSelectionMode
294//purpose :
295//=======================================================================
31e8d3c1 296void TDataXtd_Presentation::SetSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction)
f47afe53 297{
a0d0f96a 298 if (!myHasOwnSelectionMode || GetNbSelectionModes() > 1 ||
299 (GetNbSelectionModes() > 0 && mySelectionModes.First() != theSelectionMode))
f47afe53 300 {
31e8d3c1 301 if (theTransaction)
a0d0f96a 302 Backup();
303 mySelectionModes.Clear();
304 mySelectionModes.Append(theSelectionMode);
f47afe53 305 myHasOwnSelectionMode = Standard_True;
306 }
307}
308
a0d0f96a 309//=======================================================================
310//function : AddSelectionMode
311//purpose :
312//=======================================================================
313void TDataXtd_Presentation::AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction)
314{
315 if (!myHasOwnSelectionMode || !HasSelectionMode(theSelectionMode))
316 {
317 if (theTransaction)
318 Backup();
319 mySelectionModes.Append(theSelectionMode);
320 myHasOwnSelectionMode = Standard_True;
321 }
322}
f47afe53 323
324//=======================================================================
325//function : MaterialIndex
326//purpose :
327//=======================================================================
328Standard_Integer TDataXtd_Presentation::MaterialIndex() const
329{
330 return myMaterialIndex;
331}
332
333
334//=======================================================================
335//function : Transparency
336//purpose :
337//=======================================================================
338Standard_Real TDataXtd_Presentation::Transparency() const
339{
340 return myTransparency;
341}
342
343
344//=======================================================================
345//function : Color
346//purpose :
347//=======================================================================
348Quantity_NameOfColor TDataXtd_Presentation::Color() const
349{
350 return myColor;
351}
352
353
354//=======================================================================
355//function : Width
356//purpose :
357//=======================================================================
358Standard_Real TDataXtd_Presentation::Width() const
359{
360 return myWidth;
361}
362
363
364//=======================================================================
365//function : Mode
366//purpose :
367//=======================================================================
368Standard_Integer TDataXtd_Presentation::Mode() const
369{
370 return myMode;
371}
372
373
374//=======================================================================
375//function : SelectionMode
376//purpose :
377//=======================================================================
a0d0f96a 378Standard_Integer TDataXtd_Presentation::SelectionMode(const Standard_Integer index) const
f47afe53 379{
a0d0f96a 380 Standard_Integer aSelectionMode(0);
381 TColStd_ListOfInteger::Iterator itr(mySelectionModes);
382 for (Standard_Integer i = 1; itr.More() && i <= index; itr.Next(), i++)
383 {
384 if (i == index)
385 aSelectionMode = itr.Value();
386 }
387 return aSelectionMode;
f47afe53 388}
389
390
391//=======================================================================
392//function : UnsetMaterial
393//purpose :
394//=======================================================================
395void TDataXtd_Presentation::UnsetMaterial()
396{
397 if (myHasOwnMaterial)
398 {
399 Backup();
400 myHasOwnMaterial = Standard_False;
401 }
402}
403
404
405//=======================================================================
406//function : UnsetTransparency
407//purpose :
408//=======================================================================
409void TDataXtd_Presentation::UnsetTransparency()
410{
411 if (myHasOwnTransparency)
412 {
413 Backup();
414 myHasOwnTransparency = Standard_False;
415 }
416}
417
418
419//=======================================================================
420//function : UnsetColor
421//purpose :
422//=======================================================================
423void TDataXtd_Presentation::UnsetColor()
424{
425 if (myHasOwnColor)
426 {
427 Backup();
428 myHasOwnColor = Standard_False;
429 }
430}
431
432
433//=======================================================================
434//function : UnsetWidth
435//purpose :
436//=======================================================================
437void TDataXtd_Presentation::UnsetWidth()
438{
439 if (myHasOwnWidth)
440 {
441 Backup();
442 myHasOwnWidth = Standard_False;
443 }
444}
445
446
447//=======================================================================
448//function : UnsetMode
449//purpose :
450//=======================================================================
451void TDataXtd_Presentation::UnsetMode()
452{
453 if (myHasOwnMode)
454 {
455 Backup();
456 myHasOwnMode = Standard_False;
457 }
458}
459
460
461//=======================================================================
462//function : UnsetSelectionMode
463//purpose :
464//=======================================================================
465void TDataXtd_Presentation::UnsetSelectionMode()
466{
467 if (myHasOwnSelectionMode)
468 {
469 Backup();
470 myHasOwnSelectionMode = Standard_False;
a0d0f96a 471 mySelectionModes.Clear();
f47afe53 472 }
473}
474
475
476//=======================================================================
477//function : BackupCopy
478//purpose :
479//=======================================================================
480Handle(TDF_Attribute) TDataXtd_Presentation::BackupCopy() const
481{
482 Handle(TDataXtd_Presentation) aCopy = new TDataXtd_Presentation;
483
484 aCopy->myIsDisplayed = myIsDisplayed;
485 aCopy->myDriverGUID = myDriverGUID;
a0d0f96a 486 aCopy->mySelectionModes= mySelectionModes;
f47afe53 487 aCopy->myTransparency = myTransparency;
488 aCopy->myColor = myColor;
489 aCopy->myMode = myMode;
490 aCopy->myWidth = myWidth;
491 aCopy->myMaterialIndex = myMaterialIndex;
492
493 aCopy->myHasOwnColor = myHasOwnColor;
494 aCopy->myHasOwnMaterial = myHasOwnMaterial;
495 aCopy->myHasOwnWidth = myHasOwnWidth;
496 aCopy->myHasOwnMode = myHasOwnMode;
497 aCopy->myHasOwnTransparency = myHasOwnTransparency;
498 aCopy->myHasOwnSelectionMode = myHasOwnSelectionMode;
499
500 return aCopy;
501}
502
503
504//=======================================================================
505//function : NewEmpty
506//purpose :
507//=======================================================================
508Handle(TDF_Attribute) TDataXtd_Presentation::NewEmpty() const
509{
510 return new TDataXtd_Presentation();
511}
512
513
514//=======================================================================
515//function : Restore
516//purpose :
517//=======================================================================
518void TDataXtd_Presentation::Restore(const Handle(TDF_Attribute)& theAttribute)
519{
520 Handle(TDataXtd_Presentation) aPresentation =
521 Handle(TDataXtd_Presentation)::DownCast(theAttribute);
522
523 myHasOwnMaterial = aPresentation->HasOwnMaterial();
524 myMaterialIndex = aPresentation->MaterialIndex();
525
526 myHasOwnColor = aPresentation->HasOwnColor();
527 myColor = aPresentation->Color();
528
529 myHasOwnWidth = aPresentation->HasOwnWidth();
530 myWidth = aPresentation->Width();
531
532 myHasOwnMode = aPresentation->HasOwnMode();
533 myMode = aPresentation->Mode();
534
535 myHasOwnSelectionMode = aPresentation->HasOwnSelectionMode();
a0d0f96a 536 mySelectionModes = aPresentation->mySelectionModes;
f47afe53 537
538 myHasOwnTransparency = aPresentation->HasOwnTransparency();
539 myTransparency = aPresentation->Transparency();
540
541 myIsDisplayed = aPresentation->IsDisplayed();
542 myDriverGUID = aPresentation->GetDriverGUID();
543}
544
545
546//=======================================================================
547//function : Paste
548//purpose :
549//=======================================================================
550void TDataXtd_Presentation::Paste(const Handle(TDF_Attribute)& theInto,
551 const Handle(TDF_RelocationTable)&) const
552{
553 Handle(TDataXtd_Presentation) anInto =
554 Handle(TDataXtd_Presentation)::DownCast(theInto);
555
556 anInto->Backup();
557
558 if (myHasOwnMaterial)
559 {
560 anInto->myMaterialIndex = myMaterialIndex;
561 anInto->myHasOwnMaterial = Standard_True;
562 }
563 else
564 {
565 anInto->myHasOwnMaterial = Standard_False;
566 }
567
568 if (myHasOwnColor)
569 {
570 anInto->myColor = myColor;
571 anInto->myHasOwnColor = Standard_True;
572 }
573 else
574 {
575 anInto->myHasOwnColor = Standard_False;
576 }
577
578 if(myHasOwnWidth)
579 {
580 anInto->myWidth = myWidth;
581 anInto->myHasOwnWidth = Standard_True;
582 }
583 else
584 {
585 anInto->myHasOwnWidth = Standard_False;
586 }
587
588 if (myHasOwnMode)
589 {
590 anInto->myMode = myMode;
591 anInto->myHasOwnMode = Standard_True;
592 }
593 else
594 {
595 anInto->myHasOwnMode = Standard_False;
596 }
597
598 if (myHasOwnSelectionMode)
599 {
a0d0f96a 600 anInto->mySelectionModes = mySelectionModes;
f47afe53 601 anInto->myHasOwnSelectionMode = Standard_True;
602 }
603 else
604 {
605 anInto->myHasOwnSelectionMode = Standard_False;
606 }
607
608 if (myHasOwnTransparency)
609 {
610 anInto->myTransparency = myTransparency;
611 anInto->myHasOwnTransparency = Standard_True;
612 }
613 else
614 {
615 anInto->myHasOwnTransparency = Standard_False;
616 }
617
618 anInto->myIsDisplayed = myIsDisplayed;
619 anInto->myDriverGUID = myDriverGUID;
620}
a0d0f96a 621
622//=======================================================================
623//function : HasSelectionMode
624//purpose : Checks a list of selection modes.
625//=======================================================================
626Standard_Boolean TDataXtd_Presentation::HasSelectionMode(const Standard_Integer theSelectionMode) const
627{
628 Standard_Boolean ret(Standard_False);
629 TColStd_ListOfInteger::Iterator itr(mySelectionModes);
630 for (; itr.More(); itr.Next())
631 {
632 if (theSelectionMode == itr.Value())
633 ret = Standard_True;
634 }
635 return ret;
636}