0026290: It is neccessary to separate visualization part from TKCAF
[occt.git] / src / TDataXtd / TDataXtd_Presentation.cxx
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
25 IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Presentation,TDF_Attribute)
26
27 //=======================================================================
28 //function : TDataXtd_Presentation
29 //purpose  : Default constructor.
30 //=======================================================================
31 TDataXtd_Presentation::TDataXtd_Presentation()
32 : myDriverGUID           ("00000000-0000-0000-0000-000000000000"),
33   myColor                (Quantity_NOC_WHITE),
34   myMaterialIndex        (0),
35   myMode                 (0),
36   mySelectionMode        (0),
37   myTransparency         (0.0),
38   myWidth                (0.0),
39   myIsDisplayed          (Standard_False),
40   myHasOwnColor          (Standard_False),
41   myHasOwnMaterial       (Standard_False),
42   myHasOwnTransparency   (Standard_False),
43   myHasOwnWidth          (Standard_False),
44   myHasOwnMode           (Standard_False),
45   myHasOwnSelectionMode  (Standard_False)
46 {}
47
48
49 //=======================================================================
50 //function : Set
51 //purpose  : 
52 //=======================================================================
53 Handle(TDataXtd_Presentation) TDataXtd_Presentation::Set (const TDF_Label& theLabel,
54                                                                   const Standard_GUID& theDriverId)
55 {
56   Handle(TDataXtd_Presentation) aPresentation;
57
58   if ( !theLabel.FindAttribute(TDataXtd_Presentation::GetID(), aPresentation) )
59   {
60     aPresentation = new TDataXtd_Presentation();
61     theLabel.AddAttribute(aPresentation);
62   }
63
64   aPresentation->SetDriverGUID(theDriverId);
65   return aPresentation;
66 }
67
68 //=======================================================================
69 //function : Unset
70 //purpose  : 
71 //=======================================================================
72 void TDataXtd_Presentation::Unset(const TDF_Label& theLabel)
73 {
74   Handle(TDataXtd_Presentation) aPresentation;
75   if (theLabel.FindAttribute(TDataXtd_Presentation::GetID(), aPresentation))
76     theLabel.ForgetAttribute(aPresentation);
77 }
78
79
80 //=======================================================================
81 //function : GetID
82 //purpose  : 
83 //=======================================================================
84 const Standard_GUID& TDataXtd_Presentation::GetID()
85 {
86   static Standard_GUID TDataXtd_PresentationID("04fb4d00-5690-11d1-8940-080009dc3333");
87   return TDataXtd_PresentationID;
88 }
89
90
91 //=======================================================================
92 //function : ID
93 //purpose  : 
94 //=======================================================================
95 const Standard_GUID& TDataXtd_Presentation::ID() const
96 {
97   return GetID();
98 }
99
100
101 //=======================================================================
102 //function :GetDriverGUID
103 //purpose  : 
104 //=======================================================================
105 Standard_GUID TDataXtd_Presentation::GetDriverGUID() const
106 {
107   return myDriverGUID;
108 }
109
110
111 //=======================================================================
112 //function :SetDriverGUID
113 //purpose  : 
114 //=======================================================================
115 void TDataXtd_Presentation::SetDriverGUID(const Standard_GUID& theGUID)
116 {
117   if ( myDriverGUID != theGUID )
118   {
119     Backup();
120     myDriverGUID = theGUID;
121   }
122 }
123
124
125 //=======================================================================
126 //function : IsDisplayed
127 //purpose  : 
128 //=======================================================================
129 Standard_Boolean TDataXtd_Presentation::IsDisplayed() const
130 {
131   return myIsDisplayed;
132 }
133
134
135 //=======================================================================
136 //function : HasOwnMaterial
137 //purpose  : 
138 //=======================================================================
139 Standard_Boolean TDataXtd_Presentation::HasOwnMaterial() const
140 {
141   return myHasOwnMaterial;
142 }
143
144
145 //=======================================================================
146 //function : HasOwnTransparency
147 //purpose  : 
148 //=======================================================================
149 Standard_Boolean TDataXtd_Presentation::HasOwnTransparency() const
150 {
151   return myHasOwnTransparency;
152 }
153
154
155 //=======================================================================
156 //function : HasOwnColor
157 //purpose  : 
158 //=======================================================================
159 Standard_Boolean TDataXtd_Presentation::HasOwnColor() const
160 {
161   return myHasOwnColor;
162 }
163
164
165 //=======================================================================
166 //function : HasOwnWidth
167 //purpose  : 
168 //=======================================================================
169 Standard_Boolean TDataXtd_Presentation::HasOwnWidth() const
170 {
171   return myHasOwnWidth;
172 }
173
174
175 //=======================================================================
176 //function : HasOwnMode
177 //purpose  : 
178 //=======================================================================
179 Standard_Boolean TDataXtd_Presentation::HasOwnMode() const
180 {
181   return myHasOwnMode;
182 }
183
184
185 //=======================================================================
186 //function : HasOwnSelectionMode
187 //purpose  : 
188 //=======================================================================
189 Standard_Boolean TDataXtd_Presentation::HasOwnSelectionMode() const
190 {
191   return myHasOwnSelectionMode;
192 }
193
194
195 //=======================================================================
196 //function : SetDisplayed
197 //purpose  : 
198 //=======================================================================
199 void TDataXtd_Presentation::SetDisplayed(const Standard_Boolean theIsDisplayed)
200 {
201   if (myIsDisplayed != theIsDisplayed)
202   {
203     Backup();
204     myIsDisplayed = theIsDisplayed;
205   }
206 }
207
208
209 //=======================================================================
210 //function : SetMaterialIndex
211 //purpose  : 
212 //=======================================================================
213 void TDataXtd_Presentation::SetMaterialIndex(const Standard_Integer theMaterialIndex)
214 {
215   if (! myHasOwnMaterial || myMaterialIndex != theMaterialIndex)
216   {
217     Backup();
218     myMaterialIndex = theMaterialIndex;
219     myHasOwnMaterial = Standard_True;
220   }
221 }
222
223
224 //=======================================================================
225 //function : SetTransparency
226 //purpose  : 
227 //=======================================================================
228 void TDataXtd_Presentation::SetTransparency(const Standard_Real theValue)
229 {
230   if (! myHasOwnTransparency || myTransparency != theValue)
231   {
232     Backup();
233     myTransparency = theValue;
234     myHasOwnTransparency = Standard_True;
235   }
236 }
237
238
239 //=======================================================================
240 //function : SetColor
241 //purpose  : 
242 //=======================================================================
243 void TDataXtd_Presentation::SetColor(const Quantity_NameOfColor theColor)
244 {
245   if (! myHasOwnColor || myColor != theColor)
246   {
247     Backup();
248     myColor = theColor;
249     myHasOwnColor = Standard_True;
250   }
251 }
252
253
254 //=======================================================================
255 //function : SetWidth
256 //purpose  : 
257 //=======================================================================
258 void TDataXtd_Presentation::SetWidth(const Standard_Real theWidth)
259 {
260   if (! myHasOwnWidth || myWidth != theWidth)
261   {
262     Backup();
263     myWidth = theWidth;
264     myHasOwnWidth = Standard_True;
265   }
266 }
267
268
269 //=======================================================================
270 //function : SetMode
271 //purpose  : 
272 //=======================================================================
273 void TDataXtd_Presentation::SetMode(const Standard_Integer theMode)
274 {
275   if (! myHasOwnMode || myMode != theMode)
276   {
277     Backup();
278     myMode = theMode;
279     myHasOwnMode = Standard_True;
280   }
281 }
282
283
284 //=======================================================================
285 //function : SetSelectionMode
286 //purpose  : 
287 //=======================================================================
288 void TDataXtd_Presentation::SetSelectionMode(const Standard_Integer theSelectionMode)
289 {
290   if (! myHasOwnSelectionMode || mySelectionMode != theSelectionMode)
291   {
292     Backup();
293     mySelectionMode = theSelectionMode;
294     myHasOwnSelectionMode = Standard_True;
295   }
296 }
297
298
299 //=======================================================================
300 //function : MaterialIndex
301 //purpose  : 
302 //=======================================================================
303 Standard_Integer TDataXtd_Presentation::MaterialIndex() const
304 {
305   return myMaterialIndex;
306 }
307
308
309 //=======================================================================
310 //function : Transparency
311 //purpose  : 
312 //=======================================================================
313 Standard_Real TDataXtd_Presentation::Transparency() const
314 {
315   return myTransparency;
316 }
317
318
319 //=======================================================================
320 //function : Color
321 //purpose  : 
322 //=======================================================================
323 Quantity_NameOfColor TDataXtd_Presentation::Color() const
324 {
325   return myColor;
326 }
327
328
329 //=======================================================================
330 //function : Width
331 //purpose  : 
332 //=======================================================================
333 Standard_Real TDataXtd_Presentation::Width() const
334 {
335    return myWidth;
336 }
337
338
339 //=======================================================================
340 //function : Mode
341 //purpose  : 
342 //=======================================================================
343 Standard_Integer TDataXtd_Presentation::Mode() const
344 {
345   return myMode;
346 }
347
348
349 //=======================================================================
350 //function : SelectionMode
351 //purpose  : 
352 //=======================================================================
353 Standard_Integer TDataXtd_Presentation::SelectionMode() const
354 {
355   return mySelectionMode;
356 }
357
358
359 //=======================================================================
360 //function : UnsetMaterial
361 //purpose  : 
362 //=======================================================================
363 void TDataXtd_Presentation::UnsetMaterial()
364 {
365   if (myHasOwnMaterial)
366   {
367     Backup();
368     myHasOwnMaterial = Standard_False;
369   }
370 }
371
372
373 //=======================================================================
374 //function : UnsetTransparency
375 //purpose  : 
376 //=======================================================================
377 void TDataXtd_Presentation::UnsetTransparency()
378 {
379   if (myHasOwnTransparency)
380   {
381     Backup();
382     myHasOwnTransparency = Standard_False;
383   }
384 }
385
386
387 //=======================================================================
388 //function : UnsetColor
389 //purpose  : 
390 //=======================================================================
391 void TDataXtd_Presentation::UnsetColor()
392 {
393   if (myHasOwnColor)
394   {
395     Backup();
396     myHasOwnColor = Standard_False;
397   }
398 }
399
400
401 //=======================================================================
402 //function : UnsetWidth
403 //purpose  : 
404 //=======================================================================
405 void TDataXtd_Presentation::UnsetWidth()
406 {
407   if (myHasOwnWidth)
408   {
409     Backup();
410     myHasOwnWidth = Standard_False;
411   }
412 }
413
414
415 //=======================================================================
416 //function : UnsetMode
417 //purpose  : 
418 //=======================================================================
419 void TDataXtd_Presentation::UnsetMode()
420 {
421   if (myHasOwnMode)
422   {
423     Backup();
424     myHasOwnMode = Standard_False;
425   }
426 }
427
428
429 //=======================================================================
430 //function : UnsetSelectionMode
431 //purpose  : 
432 //=======================================================================
433 void TDataXtd_Presentation::UnsetSelectionMode()
434 {
435   if (myHasOwnSelectionMode)
436   {
437     Backup();
438     myHasOwnSelectionMode = Standard_False;
439   }
440 }
441
442
443 //=======================================================================
444 //function : BackupCopy
445 //purpose  : 
446 //=======================================================================
447 Handle(TDF_Attribute) TDataXtd_Presentation::BackupCopy() const
448 {
449   Handle(TDataXtd_Presentation) aCopy = new TDataXtd_Presentation;
450
451   aCopy->myIsDisplayed   = myIsDisplayed;
452   aCopy->myDriverGUID    = myDriverGUID;
453   aCopy->mySelectionMode = mySelectionMode;
454   aCopy->myTransparency  = myTransparency;
455   aCopy->myColor         = myColor;
456   aCopy->myMode          = myMode;
457   aCopy->myWidth         = myWidth;
458   aCopy->myMaterialIndex = myMaterialIndex;
459
460   aCopy->myHasOwnColor         = myHasOwnColor;
461   aCopy->myHasOwnMaterial      = myHasOwnMaterial;
462   aCopy->myHasOwnWidth         = myHasOwnWidth;
463   aCopy->myHasOwnMode          = myHasOwnMode;
464   aCopy->myHasOwnTransparency  = myHasOwnTransparency;
465   aCopy->myHasOwnSelectionMode = myHasOwnSelectionMode;
466
467   return aCopy;
468 }
469
470
471 //=======================================================================
472 //function : NewEmpty
473 //purpose  : 
474 //=======================================================================
475 Handle(TDF_Attribute) TDataXtd_Presentation::NewEmpty() const
476 {
477   return new TDataXtd_Presentation();
478 }
479
480
481 //=======================================================================
482 //function : Restore
483 //purpose  : 
484 //=======================================================================
485 void TDataXtd_Presentation::Restore(const Handle(TDF_Attribute)& theAttribute)
486 {
487   Handle(TDataXtd_Presentation) aPresentation =
488     Handle(TDataXtd_Presentation)::DownCast(theAttribute);
489
490   myHasOwnMaterial = aPresentation->HasOwnMaterial();
491   myMaterialIndex = aPresentation->MaterialIndex();
492
493   myHasOwnColor = aPresentation->HasOwnColor();
494   myColor = aPresentation->Color();
495
496   myHasOwnWidth = aPresentation->HasOwnWidth();
497   myWidth = aPresentation->Width();
498
499   myHasOwnMode = aPresentation->HasOwnMode();
500   myMode = aPresentation->Mode();
501
502   myHasOwnSelectionMode = aPresentation->HasOwnSelectionMode();
503   mySelectionMode = aPresentation->SelectionMode();
504
505   myHasOwnTransparency = aPresentation->HasOwnTransparency();
506   myTransparency = aPresentation->Transparency();
507
508   myIsDisplayed = aPresentation->IsDisplayed();
509   myDriverGUID  = aPresentation->GetDriverGUID();
510 }
511
512
513 //=======================================================================
514 //function : Paste
515 //purpose  : 
516 //=======================================================================
517 void TDataXtd_Presentation::Paste(const Handle(TDF_Attribute)& theInto,
518                                   const Handle(TDF_RelocationTable)&) const
519 {
520   Handle(TDataXtd_Presentation) anInto =
521     Handle(TDataXtd_Presentation)::DownCast(theInto);
522
523   anInto->Backup();
524
525   if (myHasOwnMaterial)
526   {
527     anInto->myMaterialIndex = myMaterialIndex;
528     anInto->myHasOwnMaterial = Standard_True;
529   }
530   else
531   {
532     anInto->myHasOwnMaterial = Standard_False;
533   }
534
535   if (myHasOwnColor)
536   {
537     anInto->myColor = myColor;
538     anInto->myHasOwnColor = Standard_True;
539   }
540   else
541   {
542     anInto->myHasOwnColor = Standard_False;
543   }
544
545   if(myHasOwnWidth)
546   {
547     anInto->myWidth = myWidth;
548     anInto->myHasOwnWidth = Standard_True;
549   }
550   else
551   {
552     anInto->myHasOwnWidth = Standard_False;
553   }
554
555   if (myHasOwnMode)
556   {
557     anInto->myMode = myMode;
558     anInto->myHasOwnMode = Standard_True;
559   }
560   else
561   {
562     anInto->myHasOwnMode = Standard_False;
563   }
564
565   if (myHasOwnSelectionMode)
566   {
567     anInto->mySelectionMode = mySelectionMode;
568     anInto->myHasOwnSelectionMode = Standard_True;
569   }
570   else
571   {
572     anInto->myHasOwnSelectionMode = Standard_False;
573   }
574
575   if (myHasOwnTransparency)
576   {
577     anInto->myTransparency = myTransparency;
578     anInto->myHasOwnTransparency = Standard_True;
579   }
580   else
581   {
582     anInto->myHasOwnTransparency = Standard_False;
583   }
584
585   anInto->myIsDisplayed = myIsDisplayed;
586   anInto->myDriverGUID  = myDriverGUID;
587 }