1 // Created on: 2008-08-15
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <MNaming_NamingRetrievalDriver_1.ixx>
17 #include <PNaming_Naming_1.hxx>
18 #include <PNaming_NamedShape.hxx>
19 #include <PNaming_HArray1OfNamedShape.hxx>
20 #include <PNaming_Name_1.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 <TNaming_Iterator.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
30 #include <CDM_MessageDriver.hxx>
32 //=======================================================================
33 //function : IntegerToShapeEnum
35 //=======================================================================
37 static TopAbs_ShapeEnum IntegerToShapeEnum (const Standard_Integer I)
41 case 0 : return TopAbs_COMPOUND;
42 case 1 : return TopAbs_COMPSOLID;
43 case 2 : return TopAbs_SOLID;
44 case 3 : return TopAbs_SHELL;
45 case 4 : return TopAbs_FACE;
46 case 5 : return TopAbs_WIRE;
47 case 6 : return TopAbs_EDGE;
48 case 7 : return TopAbs_VERTEX;
49 default : return TopAbs_SHAPE;
53 //=======================================================================
54 //function : IntegerToNameType
56 //=======================================================================
58 static TNaming_NameType IntegerToNameType (const Standard_Integer I)
62 case 0 : return TNaming_UNKNOWN;
63 case 1 : return TNaming_IDENTITY;
64 case 2 : return TNaming_MODIFUNTIL;
65 case 3 : return TNaming_GENERATION;
66 case 4 : return TNaming_INTERSECTION;
67 case 5 : return TNaming_UNION;
68 case 6 : return TNaming_SUBSTRACTION;
69 case 7 : return TNaming_CONSTSHAPE;
70 case 8 : return TNaming_FILTERBYNEIGHBOURGS;
71 case 9 : return TNaming_ORIENTATION;
72 case 10 : return TNaming_WIREIN;
74 Standard_DomainError::Raise("TNaming_NameType; enum term unknown ");
76 return TNaming_INTERSECTION;
79 //=======================================================================
80 //function : MNaming_Naming_1
82 //=======================================================================
84 MNaming_NamingRetrievalDriver_1::MNaming_NamingRetrievalDriver_1(
85 const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
89 //=======================================================================
90 //function : VersionNumber
92 //=======================================================================
94 Standard_Integer MNaming_NamingRetrievalDriver_1::VersionNumber() const
97 //=======================================================================
98 //function : SourceType
100 //=======================================================================
102 Handle(Standard_Type) MNaming_NamingRetrievalDriver_1::SourceType() const
103 { return STANDARD_TYPE(PNaming_Naming_1); }
106 //=======================================================================
107 //function : NewEmpty
109 //=======================================================================
111 Handle(TDF_Attribute) MNaming_NamingRetrievalDriver_1::NewEmpty() const
112 { return new TNaming_Naming (); }
114 //=======================================================================
115 //function : PNamingToTNaming
117 //=======================================================================
119 static void PNamingToTNaming (const Handle(PNaming_Name_1)& PN,
121 const Handle(MDF_RRelocationTable)& RelocTable)
124 TN.Type (IntegerToNameType (PN->Type ()));
125 TN.ShapeType(IntegerToShapeEnum(PN->ShapeType()));
126 Handle(TNaming_NamedShape) NS;
127 Handle(TDF_Data) aData;
128 if (!PN->Arguments().IsNull()) {
129 Standard_Integer NbArgs = PN->Arguments()->Length();
130 for (Standard_Integer i = 1; i <= NbArgs; i++) {
131 RelocTable->HasRelocation(PN->Arguments()->Value(i),NS);
133 if(aData.IsNull() && !NS.IsNull())
134 aData = NS->Label().Data();
138 Handle(TNaming_NamedShape) StopNS;
139 if (!PN->StopNamedShape().IsNull())
140 RelocTable->HasRelocation(PN->StopNamedShape(),StopNS);
141 TN.StopNamedShape(StopNS);
142 TN.Index(PN->Index());
144 TDF_Label tLab; // Null label.
145 Handle(PCollection_HAsciiString) pEntry = PN->ContextLabel();
146 if (!pEntry.IsNull()) {
147 TCollection_AsciiString entry = pEntry->Convert();
149 TDF_Tool::Label(aData,entry,tLab);
151 TN.ContextLabel(tLab);
154 //=======================================================================
157 //=======================================================================
159 void MNaming_NamingRetrievalDriver_1::Paste (
160 const Handle(PDF_Attribute)& Source,
161 const Handle(TDF_Attribute)& Target,
162 const Handle(MDF_RRelocationTable)& RelocTable) const
164 Handle(PNaming_Naming_1) PF = Handle(PNaming_Naming_1)::DownCast(Source);
165 Handle(TNaming_Naming) F = Handle(TNaming_Naming)::DownCast(Target);
166 PNamingToTNaming (PF->GetName(),F->ChangeName(),RelocTable);
167 // Orientation processing
168 Handle(TNaming_NamedShape) aNS;
169 if(F->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
170 #ifdef OCCT_DEBUG_ORIENT
171 const TDF_Label& aLab = aNS->Label();
172 TCollection_AsciiString entry;
173 TDF_Tool::Entry(aLab, entry);
174 cout << "Label = " << entry << " Evolution = " <<aNS->Evolution() << " IsEmpty = " << aNS->IsEmpty() <<endl;
176 if(!aNS->IsEmpty()) {
177 TNaming_Iterator itL (aNS);
178 for (; itL.More(); itL.Next()) {
179 const TopoDS_Shape& S = itL.NewShape();
180 if (S.IsNull()) continue;
181 if(aNS->Evolution() == TNaming_SELECTED) {
182 if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX &&
183 !itL.OldShape().IsNull() && itL.OldShape().ShapeType() == TopAbs_VERTEX ) {//OR-N
184 TopAbs_Orientation OrientationToApply = itL.OldShape().Orientation();
185 #ifdef OCCT_DEBUG_ORIENT
186 cout <<"Retrieved Orientation = " << OrientationToApply <<endl;
188 F->ChangeName().Orientation(OrientationToApply);