b311480e |
1 | // Created on: 2004-11-24 |
2 | // Created by: Edward AGAPOV |
973c2be1 |
3 | // Copyright (c) 2004-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // The original implementation Copyright: (C) RINA S.p.A |
17 | |
18 | |
19 | #include "XmlTObjDrivers_ModelDriver.hxx" |
20 | |
21 | #include <CDM_MessageDriver.hxx> |
22 | #include <XmlObjMgt_Persistent.hxx> |
23 | #include <XmlObjMgt_RRelocationTable.hxx> |
24 | #include <XmlObjMgt.hxx> |
25 | #include <Standard_GUID.hxx> |
26 | #include <TDF_Attribute.hxx> |
27 | |
28 | #include <TObj_TModel.hxx> |
29 | #include <TObj_Model.hxx> |
30 | #include <TObj_Assistant.hxx> |
31 | |
ec357c5c |
32 | |
33 | |
7fd59977 |
34 | |
92efcf78 |
35 | IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_ModelDriver,XmlMDF_ADriver) |
36 | |
7fd59977 |
37 | //======================================================================= |
38 | //function : XmlTObjDrivers_ModelDriver |
39 | //purpose : constructor |
40 | //======================================================================= |
41 | |
42 | XmlTObjDrivers_ModelDriver::XmlTObjDrivers_ModelDriver |
43 | (const Handle(CDM_MessageDriver)& theMessageDriver) |
44 | : XmlMDF_ADriver( theMessageDriver, NULL) |
45 | { |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : NewEmpty |
50 | //purpose : Creates a new attribute |
51 | //======================================================================= |
52 | |
53 | Handle(TDF_Attribute) XmlTObjDrivers_ModelDriver::NewEmpty() const |
54 | { |
55 | return new TObj_TModel; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : Paste |
60 | //purpose : Translate the contents of <aSource> and put it |
61 | // into <aTarget>, using the relocation table |
62 | // <aRelocTable> to keep the sharings. |
63 | // Set CurrentModel of TObj_Assistant into Target TObj_TModel |
64 | // if its GUID and GUID stored in Source are same |
65 | //======================================================================= |
66 | |
67 | Standard_Boolean XmlTObjDrivers_ModelDriver::Paste |
68 | (const XmlObjMgt_Persistent& Source, |
69 | const Handle(TDF_Attribute)& Target, |
70 | XmlObjMgt_RRelocationTable& /*RelocTable*/) const |
71 | { |
72 | TCollection_ExtendedString aString; |
73 | if (XmlObjMgt::GetExtendedString (Source, aString)) |
74 | { |
75 | Standard_GUID aGUID (aString.ToExtString()); |
76 | Handle(TObj_Model) aCurrentModel = TObj_Assistant::GetCurrentModel(); |
77 | if (aGUID == aCurrentModel->GetGUID()) |
78 | { |
79 | Handle(TObj_TModel) aTModel = Handle(TObj_TModel)::DownCast( Target ); |
80 | aCurrentModel->SetLabel ( aTModel->Label() ); |
81 | aTModel->Set( aCurrentModel ); |
82 | return Standard_True; |
83 | } |
84 | WriteMessage("TObj_TModel retrieval: wrong model GUID"); |
85 | return Standard_False; |
86 | } |
87 | WriteMessage("error retrieving ExtendedString for type TObj_TModel"); |
88 | return Standard_False; |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Paste |
93 | //purpose : Translate the contents of <aSource> and put it |
94 | // into <aTarget>, using the relocation table |
95 | // <aRelocTable> to keep the sharings. |
96 | // a Model is stored as its GUID |
97 | //======================================================================= |
98 | |
99 | void XmlTObjDrivers_ModelDriver::Paste |
100 | (const Handle(TDF_Attribute)& Source, |
101 | XmlObjMgt_Persistent& Target, |
102 | XmlObjMgt_SRelocationTable& /*RelocTable*/) const |
103 | { |
104 | Handle(TObj_TModel) aTModel = |
105 | Handle(TObj_TModel)::DownCast( Source ); |
106 | Handle(TObj_Model) aModel = aTModel->Model(); |
107 | |
108 | // Store model GUID. |
109 | Standard_PCharacter aPGuidString = new Standard_Character[256]; |
110 | aModel->GetGUID().ToCString( aPGuidString ); |
09599901 |
111 | XmlObjMgt::SetExtendedString (Target, aPGuidString); |
7fd59977 |
112 | delete []aPGuidString; |
113 | } |