7dcac1df |
1 | // Created on: 2008-08-15 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2008-2014 OPEN CASCADE SAS |
7dcac1df |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7dcac1df |
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. |
7dcac1df |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7dcac1df |
15 | |
16 | #include <MNaming_NamingRetrievalDriver_2.ixx> |
17 | #include <PNaming_Naming_2.hxx> |
18 | #include <PNaming_NamedShape.hxx> |
19 | #include <PNaming_HArray1OfNamedShape.hxx> |
20 | #include <PNaming_Name_2.hxx> |
21 | #include <PCollection_HAsciiString.hxx> |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TDF_Tool.hxx> |
24 | #include <TNaming_NamedShape.hxx> |
25 | #include <Standard_NoSuchObject.hxx> |
26 | #include <TNaming_Naming.hxx> |
27 | #include <TNaming_NameType.hxx> |
28 | #include <TopAbs_ShapeEnum.hxx> |
29 | #include <CDM_MessageDriver.hxx> |
30 | |
31 | //======================================================================= |
32 | //function : IntegerToShapeEnum |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | static TopAbs_ShapeEnum IntegerToShapeEnum (const Standard_Integer I) |
37 | { |
38 | switch(I) |
39 | { |
40 | case 0 : return TopAbs_COMPOUND; |
41 | case 1 : return TopAbs_COMPSOLID; |
42 | case 2 : return TopAbs_SOLID; |
43 | case 3 : return TopAbs_SHELL; |
44 | case 4 : return TopAbs_FACE; |
45 | case 5 : return TopAbs_WIRE; |
46 | case 6 : return TopAbs_EDGE; |
47 | case 7 : return TopAbs_VERTEX; |
498ce76b |
48 | default : return TopAbs_SHAPE; |
7dcac1df |
49 | } |
7dcac1df |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : IntegerToNameType |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | static TNaming_NameType IntegerToNameType (const Standard_Integer I) |
58 | { |
59 | switch(I) |
60 | { |
61 | case 0 : return TNaming_UNKNOWN; |
62 | case 1 : return TNaming_IDENTITY; |
63 | case 2 : return TNaming_MODIFUNTIL; |
64 | case 3 : return TNaming_GENERATION; |
65 | case 4 : return TNaming_INTERSECTION; |
66 | case 5 : return TNaming_UNION; |
67 | case 6 : return TNaming_SUBSTRACTION; |
68 | case 7 : return TNaming_CONSTSHAPE; |
69 | case 8 : return TNaming_FILTERBYNEIGHBOURGS; |
70 | case 9 : return TNaming_ORIENTATION; |
71 | case 10 : return TNaming_WIREIN; |
72 | default : |
73 | Standard_DomainError::Raise("TNaming_NameType; enum term unknown "); |
74 | } |
75 | return TNaming_UNKNOWN; |
76 | } |
77 | //======================================================================= |
78 | //function : IntegerToOrientation |
79 | //purpose : |
80 | //======================================================================= |
81 | static TopAbs_Orientation IntegerToOrientation (const Standard_Integer Or) |
82 | { |
83 | switch(Or) |
84 | { |
85 | case 0 : return TopAbs_FORWARD; |
86 | case 1 : return TopAbs_REVERSED; |
87 | case 2 : return TopAbs_INTERNAL; |
88 | case 3 : return TopAbs_EXTERNAL; |
89 | default : |
90 | Standard_DomainError::Raise("PNaming_Name::myOrientation; enum term unknown "); |
91 | } |
92 | return TopAbs_FORWARD; |
93 | } |
94 | //======================================================================= |
95 | //function : MNaming_Naming_2 |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | MNaming_NamingRetrievalDriver_2::MNaming_NamingRetrievalDriver_2( |
100 | const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver) |
101 | { |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : VersionNumber |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | Standard_Integer MNaming_NamingRetrievalDriver_2::VersionNumber() const |
110 | { return 0; } |
111 | |
112 | //======================================================================= |
113 | //function : SourceType |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | Handle(Standard_Type) MNaming_NamingRetrievalDriver_2::SourceType() const |
118 | { return STANDARD_TYPE(PNaming_Naming_2); } |
119 | |
120 | |
121 | //======================================================================= |
122 | //function : NewEmpty |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | Handle(TDF_Attribute) MNaming_NamingRetrievalDriver_2::NewEmpty() const |
127 | { return new TNaming_Naming (); } |
128 | |
129 | //======================================================================= |
130 | //function : PNamingToTNaming |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | static void PNamingToTNaming (const Handle(PNaming_Name_2)& PN, |
135 | TNaming_Name& TN, |
136 | const Handle(MDF_RRelocationTable)& RelocTable) |
137 | |
138 | { |
139 | TN.Type (IntegerToNameType (PN->Type ())); |
140 | TN.ShapeType(IntegerToShapeEnum(PN->ShapeType())); |
141 | Handle(TNaming_NamedShape) NS; |
142 | Handle(TDF_Data) aData; |
143 | if (!PN->Arguments().IsNull()) { |
144 | Standard_Integer NbArgs = PN->Arguments()->Length(); |
145 | for (Standard_Integer i = 1; i <= NbArgs; i++) { |
146 | RelocTable->HasRelocation(PN->Arguments()->Value(i),NS); |
147 | TN.Append(NS); |
148 | if(aData.IsNull() && !NS.IsNull()) |
149 | aData = NS->Label().Data(); |
150 | } |
151 | } |
152 | |
153 | Handle(TNaming_NamedShape) StopNS; |
154 | if (!PN->StopNamedShape().IsNull()) |
155 | RelocTable->HasRelocation(PN->StopNamedShape(),StopNS); |
156 | TN.StopNamedShape(StopNS); |
157 | TN.Index(PN->Index()); |
158 | |
159 | TDF_Label tLab; // Null label. |
160 | Handle(PCollection_HAsciiString) pEntry = PN->ContextLabel(); |
161 | if (!pEntry.IsNull()) { |
162 | TCollection_AsciiString entry = pEntry->Convert(); |
163 | if(!aData.IsNull()) |
164 | TDF_Tool::Label(aData,entry,tLab); |
165 | } |
166 | TN.ContextLabel(tLab); |
167 | TN.Orientation(IntegerToOrientation (PN->Orientation ())); |
168 | } |
169 | |
170 | //======================================================================= |
171 | //function : Paste |
172 | //purpose : |
173 | //======================================================================= |
174 | |
175 | void MNaming_NamingRetrievalDriver_2::Paste ( |
176 | const Handle(PDF_Attribute)& Source, |
177 | const Handle(TDF_Attribute)& Target, |
178 | const Handle(MDF_RRelocationTable)& RelocTable) const |
179 | { |
180 | Handle(PNaming_Naming_2) PF = Handle(PNaming_Naming_2)::DownCast(Source); |
181 | Handle(TNaming_Naming) F = Handle(TNaming_Naming)::DownCast(Target); |
182 | PNamingToTNaming (PF->GetName(),F->ChangeName(),RelocTable); |
183 | } |
184 | |