0025418: Debug output to be limited to OCC development environment
[occt.git] / src / MNaming / MNaming_NamingRetrievalDriver_1.cxx
CommitLineData
b311480e 1// Created on: 2008-08-15
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2008-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.
7fd59977 15
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>
7dcac1df 28#include <TNaming_Iterator.hxx>
7fd59977 29#include <TopAbs_ShapeEnum.hxx>
30#include <CDM_MessageDriver.hxx>
31
32//=======================================================================
33//function : IntegerToShapeEnum
34//purpose :
35//=======================================================================
36
37static TopAbs_ShapeEnum IntegerToShapeEnum (const Standard_Integer I)
38{
39 switch(I)
40 {
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;
498ce76b 49 default : return TopAbs_SHAPE;
7fd59977 50 }
7fd59977 51}
52
53//=======================================================================
54//function : IntegerToNameType
55//purpose :
56//=======================================================================
57
58static TNaming_NameType IntegerToNameType (const Standard_Integer I)
59{
60 switch(I)
61 {
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;
73 default :
7dcac1df 74 Standard_DomainError::Raise("TNaming_NameType; enum term unknown ");
7fd59977 75 }
76 return TNaming_INTERSECTION;
77}
78
79//=======================================================================
80//function : MNaming_Naming_1
81//purpose :
82//=======================================================================
83
84MNaming_NamingRetrievalDriver_1::MNaming_NamingRetrievalDriver_1(
85 const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
86{
87}
88
89//=======================================================================
90//function : VersionNumber
91//purpose :
92//=======================================================================
93
94Standard_Integer MNaming_NamingRetrievalDriver_1::VersionNumber() const
95{ return 0; }
96
97//=======================================================================
98//function : SourceType
99//purpose :
100//=======================================================================
101
102Handle(Standard_Type) MNaming_NamingRetrievalDriver_1::SourceType() const
103{ return STANDARD_TYPE(PNaming_Naming_1); }
104
105
106//=======================================================================
107//function : NewEmpty
108//purpose :
109//=======================================================================
110
111Handle(TDF_Attribute) MNaming_NamingRetrievalDriver_1::NewEmpty() const
112{ return new TNaming_Naming (); }
113
114//=======================================================================
115//function : PNamingToTNaming
116//purpose :
117//=======================================================================
118
119static void PNamingToTNaming (const Handle(PNaming_Name_1)& PN,
120 TNaming_Name& TN,
121 const Handle(MDF_RRelocationTable)& RelocTable)
122
123{
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);
132 TN.Append(NS);
133 if(aData.IsNull() && !NS.IsNull())
134 aData = NS->Label().Data();
135 }
136 }
137
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());
143
144 TDF_Label tLab; // Null label.
145 Handle(PCollection_HAsciiString) pEntry = PN->ContextLabel();
146 if (!pEntry.IsNull()) {
147 TCollection_AsciiString entry = pEntry->Convert();
148 if(!aData.IsNull())
149 TDF_Tool::Label(aData,entry,tLab);
150 }
151 TN.ContextLabel(tLab);
152}
153
154//=======================================================================
155//function : Paste
156//purpose :
157//=======================================================================
7dcac1df 158//#define DEB_ORIENT
7fd59977 159void MNaming_NamingRetrievalDriver_1::Paste (
160 const Handle(PDF_Attribute)& Source,
161 const Handle(TDF_Attribute)& Target,
162 const Handle(MDF_RRelocationTable)& RelocTable) const
163{
164 Handle(PNaming_Naming_1) PF = Handle(PNaming_Naming_1)::DownCast(Source);
7dcac1df 165 Handle(TNaming_Naming) F = Handle(TNaming_Naming)::DownCast(Target);
7fd59977 166 PNamingToTNaming (PF->GetName(),F->ChangeName(),RelocTable);
7dcac1df 167 // Orientation processing
168 Handle(TNaming_NamedShape) aNS;
169 if(F->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
0797d9d3 170#ifdef OCCT_DEBUG_ORIENT
7dcac1df 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;
175#endif
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();
0797d9d3 185#ifdef OCCT_DEBUG_ORIENT
7dcac1df 186 cout <<"Retrieved Orientation = " << OrientationToApply <<endl;
187#endif
188 F->ChangeName().Orientation(OrientationToApply);
189 }
190 }
191 }
192 }
193 }
194 //
7fd59977 195}
196