7fd59977 |
1 | // File: MNaming_NamingStorageDriver.cxx |
2 | // Created: Wed Sep 17 17:17:38 1997 |
3 | // Author: Isabelle GRIGNON |
4 | // <isg@bigbox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | #include <MNaming_NamingStorageDriver.ixx> |
8 | #include <PNaming_Naming_1.hxx> |
9 | #include <PCollection_HAsciiString.hxx> |
10 | #include <Standard_NoSuchObject.hxx> |
11 | #include <TDF_Tool.hxx> |
12 | #include <TNaming_Naming.hxx> |
13 | #include <TCollection_AsciiString.hxx> |
14 | #include <TNaming_Name.hxx> |
15 | #include <PNaming_Name_1.hxx> |
16 | #include <PNaming_NamedShape.hxx> |
17 | #include <TNaming_NamedShape.hxx> |
18 | #include <TNaming_ListOfNamedShape.hxx> |
19 | #include <TNaming_ListIteratorOfListOfNamedShape.hxx> |
20 | #include <CDM_MessageDriver.hxx> |
21 | #include <PNaming_HArray1OfNamedShape.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : IntegerToShapeEnum |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | static Standard_Integer ShapeEnumToInteger (const TopAbs_ShapeEnum I) |
29 | { |
30 | switch(I) |
31 | { |
32 | case TopAbs_COMPOUND : return 0; |
33 | case TopAbs_COMPSOLID : return 1; |
34 | case TopAbs_SOLID : return 2; |
35 | case TopAbs_SHELL : return 3; |
36 | case TopAbs_FACE : return 4; |
37 | case TopAbs_WIRE : return 5; |
38 | case TopAbs_EDGE : return 6; |
39 | case TopAbs_VERTEX : return 7; |
40 | case TopAbs_SHAPE : return 8; |
41 | } |
42 | return 8; |
43 | } |
44 | |
45 | //======================================================================= |
46 | //function : IntegerToNameType |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | static Standard_Integer NameTypeToInteger (const TNaming_NameType I) |
51 | { |
52 | switch(I) |
53 | { |
54 | case TNaming_UNKNOWN : return 0; |
55 | case TNaming_IDENTITY : return 1; |
56 | case TNaming_MODIFUNTIL : return 2; |
57 | case TNaming_GENERATION : return 3; |
58 | case TNaming_INTERSECTION : return 4; |
59 | case TNaming_UNION : return 5; |
60 | case TNaming_SUBSTRACTION : return 6; |
61 | case TNaming_CONSTSHAPE : return 7; |
62 | case TNaming_FILTERBYNEIGHBOURGS : return 8; |
63 | case TNaming_ORIENTATION : return 9; |
64 | case TNaming_WIREIN : return 10; |
65 | default : |
66 | Standard_DomainError::Raise("TNaming_NameType; enum term unknown "); |
67 | } |
68 | return 0; |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : MNaming_NamingStorageDriver |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | MNaming_NamingStorageDriver::MNaming_NamingStorageDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ASDriver(theMsgDriver) |
77 | { |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : VersionNumber |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | Standard_Integer MNaming_NamingStorageDriver::VersionNumber() const |
86 | { return 0; } |
87 | |
88 | //======================================================================= |
89 | //function : SourceType |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Handle(Standard_Type) MNaming_NamingStorageDriver::SourceType() const |
94 | { return STANDARD_TYPE(TNaming_Naming); } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : NewEmpty |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | Handle(PDF_Attribute) MNaming_NamingStorageDriver::NewEmpty() const |
103 | { return new PNaming_Naming_1 (); } |
104 | |
105 | |
106 | //======================================================================= |
107 | //function : TNamingToPNaming |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | static void TNamingToPNaming (const TNaming_Name& TN, |
112 | Handle(PNaming_Name_1)& PN, |
113 | const Handle(MDF_SRelocationTable)& RelocTable) |
114 | { |
115 | PN = new PNaming_Name_1(); |
116 | PN->Type (NameTypeToInteger (TN.Type ())); |
117 | PN->ShapeType(ShapeEnumToInteger(TN.ShapeType())); |
118 | |
119 | Handle (PNaming_NamedShape) PNS; |
120 | Standard_Integer NbArgs = TN.Arguments().Extent(); |
121 | |
122 | if (NbArgs > 0) { |
123 | Handle(PNaming_HArray1OfNamedShape) TabArgs = new PNaming_HArray1OfNamedShape(1,NbArgs); |
124 | PN->Arguments(TabArgs); |
125 | |
126 | Standard_Integer i = 1; |
127 | for (TNaming_ListIteratorOfListOfNamedShape it (TN.Arguments()); it.More(); it.Next()) { |
128 | RelocTable->HasRelocation(it.Value(),PNS); |
129 | TabArgs->SetValue(i++,PNS); |
130 | } |
131 | } |
132 | |
133 | Handle (PNaming_NamedShape) StopPNS; |
134 | if (!TN.StopNamedShape().IsNull()) |
135 | RelocTable->HasRelocation(TN.StopNamedShape(),StopPNS); |
136 | PN->StopNamedShape(StopPNS); |
137 | |
138 | PN->Index(TN.Index()); |
139 | Handle(PCollection_HAsciiString) pEntry; // Null handle. |
140 | if(!TN.ContextLabel().IsNull()) { |
141 | TCollection_AsciiString entry; |
142 | TDF_Tool::Entry(TN.ContextLabel(),entry); |
143 | pEntry = new PCollection_HAsciiString(entry); |
144 | |
145 | } |
146 | PN->ContextLabel(pEntry); |
147 | } |
148 | |
149 | //======================================================================= |
150 | //function : Paste |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | void MNaming_NamingStorageDriver::Paste ( |
155 | const Handle(TDF_Attribute)& Source, |
156 | const Handle(PDF_Attribute)& Target, |
157 | const Handle(MDF_SRelocationTable)& RelocTable) const |
158 | { |
159 | Handle(PNaming_Naming_1) PF = Handle(PNaming_Naming_1)::DownCast(Target); |
160 | Handle(TNaming_Naming) F = Handle(TNaming_Naming)::DownCast(Source); |
161 | Handle(PNaming_Name_1) PN ; |
162 | TNamingToPNaming (F->GetName(), PN ,RelocTable); |
163 | PF->SetName(PN); |
164 | } |
165 | |