0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / BinMPrsStd / BinMPrsStd_AISPresentationDriver.cxx
1 // Created on: 2004-05-17
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BinMPrsStd_AISPresentationDriver.ixx>
17 #include <TPrsStd_AISPresentation.hxx>
18 #include <Graphic3d_NameOfMaterial.hxx>
19 #include <Quantity_NameOfColor.hxx>
20 #include <CDM_MessageDriver.hxx>
21 //=======================================================================
22 //function : BinMDataStd_AISPresentationDriver
23 //purpose  : Constructor
24 //=======================================================================
25
26 BinMPrsStd_AISPresentationDriver::BinMPrsStd_AISPresentationDriver
27                         (const Handle(CDM_MessageDriver)& theMsgDriver)
28      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TPrsStd_AISPresentation)->Name())
29 {
30 }
31
32 //=======================================================================
33 //function : NewEmpty
34 //purpose  : 
35 //=======================================================================
36
37 Handle(TDF_Attribute) BinMPrsStd_AISPresentationDriver::NewEmpty() const
38 {
39   return new TPrsStd_AISPresentation();
40 }
41
42 //=======================================================================
43 //function : Paste
44 //purpose  : persistent -> transient (retrieve)
45 //=======================================================================
46
47 Standard_Boolean BinMPrsStd_AISPresentationDriver::Paste
48                                 (const BinObjMgt_Persistent&  theSource,
49                                  const Handle(TDF_Attribute)& theTarget,
50                                  BinObjMgt_RRelocationTable&  ) const
51 {
52   Handle(TPrsStd_AISPresentation) anAtt = Handle(TPrsStd_AISPresentation)::DownCast(theTarget);
53   Standard_Integer aValue;
54 //Display status
55   Standard_Boolean ok = theSource >> aValue;
56   if (!ok) return ok;
57   anAtt->SetDisplayed((Standard_Boolean)aValue);
58
59 //GUID
60   Standard_GUID aGUID;
61   ok = theSource >> aGUID;
62   if (!ok) return ok;
63   anAtt->SetDriverGUID(aGUID);
64
65 //Color
66   ok = theSource >> aValue;
67   if (!ok) return ok;
68   if(aValue != -1)  anAtt->SetColor( (Quantity_NameOfColor)(aValue) );
69   else anAtt->UnsetColor();
70
71 //Material
72   ok = theSource >> aValue;
73   if (!ok) return ok;
74   if(aValue != -1)  anAtt->SetMaterial( (Graphic3d_NameOfMaterial)(aValue) );
75   else anAtt->UnsetMaterial();
76
77 //Transparency
78   Standard_Real aRValue;
79   ok = theSource >> aRValue;
80   if (!ok) return ok;
81   if(aRValue != -1.)  anAtt->SetTransparency(aRValue);
82   else anAtt->UnsetTransparency(); 
83
84 //Width
85   ok = theSource >> aRValue;
86   if (!ok) return ok;
87   if(aRValue != -1.)  anAtt->SetWidth( aRValue );
88   else anAtt->UnsetWidth(); 
89
90 //Mode
91   ok = theSource >> aValue;
92   if (!ok) return ok;
93   if(aValue != -1)  anAtt->SetMode(aValue);
94   else anAtt->UnsetMode();
95
96   return ok;
97 }
98
99 //=======================================================================
100 //function : Paste
101 //purpose  : transient -> persistent (store)
102 //=======================================================================
103
104 void BinMPrsStd_AISPresentationDriver::Paste (const Handle(TDF_Attribute)& theSource,
105                                        BinObjMgt_Persistent&        theTarget,
106                                        BinObjMgt_SRelocationTable&  ) const
107 {
108   Handle(TPrsStd_AISPresentation) anAtt = Handle(TPrsStd_AISPresentation)::DownCast(theSource);
109 //1
110   theTarget.PutBoolean(anAtt->IsDisplayed());//Bool
111 //2
112   theTarget.PutGUID(anAtt->GetDriverGUID());//GUID
113 //3
114   if(anAtt->HasOwnColor()) 
115     theTarget.PutInteger((Standard_Integer)anAtt->Color());//Color
116   else theTarget.PutInteger(-1);
117 //4
118  if(anAtt->HasOwnMaterial())
119    theTarget.PutInteger((Standard_Integer)anAtt->Material());
120  else theTarget.PutInteger(-1);
121 //5
122   if(anAtt->HasOwnTransparency())
123     theTarget.PutReal(anAtt->Transparency()); //Real
124   else theTarget.PutReal(-1.);
125 //6
126   if(anAtt->HasOwnWidth())
127     theTarget.PutReal(anAtt->Width());// Real
128   else theTarget.PutReal(-1.);
129 //7
130   if(anAtt->HasOwnMode())
131     theTarget.PutInteger(anAtt->Mode()); //Int
132   else theTarget.PutInteger(-1);
133 }