508cb2297749d4d91e18ad0728d77630e450c9e3
[occt.git] / src / MNaming / MNaming_NamingRetrievalDriver.cxx
1 // Created on: 1997-09-17
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <MNaming_NamingRetrievalDriver.ixx>
24 #include <PNaming_Naming.hxx>
25 #include <PNaming_NamedShape.hxx>
26 #include <PNaming_HArray1OfNamedShape.hxx>
27 #include <PNaming_Name.hxx>
28 #include <TNaming_NamedShape.hxx>
29 #include <Standard_NoSuchObject.hxx>
30 #include <TNaming_Naming.hxx>
31 #include <TNaming_NameType.hxx>
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <CDM_MessageDriver.hxx>
34
35 //=======================================================================
36 //function : IntegerToShapeEnum
37 //purpose  : 
38 //=======================================================================
39
40 static TopAbs_ShapeEnum IntegerToShapeEnum (const Standard_Integer I)
41 {
42   switch(I)
43     {
44     case  0 : return TopAbs_COMPOUND;
45     case  1 : return TopAbs_COMPSOLID;
46     case  2 : return TopAbs_SOLID;
47     case  3 : return TopAbs_SHELL;
48     case  4 : return TopAbs_FACE;
49     case  5 : return TopAbs_WIRE;
50     case  6 : return TopAbs_EDGE;
51     case  7 : return TopAbs_VERTEX;
52       default :
53         return TopAbs_SHAPE;
54     }
55   return TopAbs_SHAPE;
56 }
57
58 //=======================================================================
59 //function : IntegerToNameType
60 //purpose  : 
61 //=======================================================================
62
63 static  TNaming_NameType IntegerToNameType (const Standard_Integer I) 
64 {
65   switch(I)
66     {
67     case  0 : return TNaming_UNKNOWN;  
68     case  1 : return TNaming_IDENTITY;
69     case  2 : return TNaming_MODIFUNTIL;
70     case  3 : return TNaming_GENERATION;
71     case  4 : return TNaming_INTERSECTION;
72     case  5 : return TNaming_UNION;
73     case  6 : return TNaming_SUBSTRACTION;
74     case  7 : return TNaming_CONSTSHAPE; 
75     case  8 : return TNaming_FILTERBYNEIGHBOURGS;
76     case  9 : return TNaming_ORIENTATION;
77     case  10: return TNaming_WIREIN;
78     case  11: return TNaming_SHELLIN;
79       default :
80         Standard_DomainError::Raise("TNaming_NameType; enum term unknown ");
81     }
82   return TNaming_INTERSECTION;
83 }
84
85 //=======================================================================
86 //function : MNaming_Naming
87 //purpose  : 
88 //=======================================================================
89
90 MNaming_NamingRetrievalDriver::MNaming_NamingRetrievalDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
91 {
92 }
93
94 //=======================================================================
95 //function : VersionNumber
96 //purpose  : 
97 //=======================================================================
98
99 Standard_Integer MNaming_NamingRetrievalDriver::VersionNumber() const
100 { return 0; }
101
102 //=======================================================================
103 //function : SourceType
104 //purpose  : 
105 //=======================================================================
106
107 Handle(Standard_Type) MNaming_NamingRetrievalDriver::SourceType() const
108 { return STANDARD_TYPE(PNaming_Naming);  }
109
110
111 //=======================================================================
112 //function : NewEmpty
113 //purpose  : 
114 //=======================================================================
115
116 Handle(TDF_Attribute) MNaming_NamingRetrievalDriver::NewEmpty() const
117 { return new TNaming_Naming (); }
118
119 //=======================================================================
120 //function : PNamingToTNaming
121 //purpose  : 
122 //=======================================================================
123
124 static void PNamingToTNaming (const Handle(PNaming_Name)& PN,
125                               TNaming_Name&               TN,
126                               const Handle(MDF_RRelocationTable)& RelocTable)
127
128 {
129   TN.Type     (IntegerToNameType (PN->Type     ()));
130   TN.ShapeType(IntegerToShapeEnum(PN->ShapeType()));
131   Handle(TNaming_NamedShape) NS;
132   
133   if (!PN->Arguments().IsNull()) {
134     Standard_Integer NbArgs = PN->Arguments()->Length();
135     for (Standard_Integer i = 1; i <= NbArgs; i++) {
136       RelocTable->HasRelocation(PN->Arguments()->Value(i),NS);
137       TN.Append(NS);
138     }
139   }
140
141   Handle(TNaming_NamedShape) StopNS;
142   if (!PN->StopNamedShape().IsNull()) 
143     RelocTable->HasRelocation(PN->StopNamedShape(),StopNS);
144   TN.StopNamedShape(StopNS);  
145   TN.Index(PN->Index());
146 }
147
148 //=======================================================================
149 //function : Paste
150 //purpose  : 
151 //=======================================================================
152
153 void MNaming_NamingRetrievalDriver::Paste (
154   const Handle(PDF_Attribute)&        Source,
155   const Handle(TDF_Attribute)&        Target,
156   const Handle(MDF_RRelocationTable)& RelocTable) const
157 {
158   //MDesign_FunctionRetrievalDriver::Paste (Source,Target,RelocTable);
159   Handle(PNaming_Naming) PF = Handle(PNaming_Naming)::DownCast(Source);
160   Handle(TNaming_Naming) F  = Handle(TNaming_Naming)::DownCast(Target);  
161   PNamingToTNaming (PF->GetName(),F->ChangeName(),RelocTable);
162 }
163
164
165