0024624: Lost word in license statement in source files
[occt.git] / src / QADNaming / QADNaming.cxx
CommitLineData
b311480e 1// Created on: 1997-01-09
2// Created by: VAUTHIER Jean-Claude & Fricaud Yves
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <stdio.h>
18
19#include <QADNaming.ixx>
20
21#include <DDF.hxx>
22
23#include <Draw.hxx>
24#include <TColStd_HArray1OfInteger.hxx>
25#include <TColStd_ListIteratorOfListOfInteger.hxx>
26#include <TColStd_ListOfInteger.hxx>
27#include <TCollection_AsciiString.hxx>
28#include <TDF_ChildIterator.hxx>
29#include <TDF_LabelList.hxx>
30#include <TDF_LabelMap.hxx>
31#include <TDF_Tool.hxx>
32#include <TNaming_Iterator.hxx>
33#include <TNaming_Tool.hxx>
34#include <TNaming_NamedShape.hxx>
35#include <DBRep.hxx>
36#include <TopExp_Explorer.hxx>
37#include <TopoDS_Vertex.hxx>
38#include <TopoDS.hxx>
39#include <BRep_Tool.hxx>
40#include <gp_Pnt.hxx>
41
42//=======================================================================
43//function : GetShape
44//purpose :
45//=======================================================================
46
47void QADNaming::GetShape (const Standard_CString LabelName,
48 const Handle(TDF_Data)& DF,
49 TopTools_ListOfShape& L)
50{
51 L.Clear();
52 TDF_Label Label;
53 Standard_Boolean Found = DDF::AddLabel (DF, LabelName, Label);
54 if (Found) {
55 TNaming_Iterator it (Label, DF->Transaction ());
56 for (; it.More(); it.Next()) {
57 L.Append(it.NewShape());
58 }
59 }
60}
61
62//=======================================================================
63//function : BuildMap
64//purpose :
65//=======================================================================
66
67void QADNaming_BuildMap(TDF_LabelMap& Updated,
68 const TDF_Label& Lab)
69{
70 TDF_ChildIterator it(Lab);
71 for (; it.More(); it.Next()) {
72 Updated.Add(it.Value());
73 QADNaming_BuildMap(Updated,it.Value());
74 }
75}
76
77//=======================================================================
78//function : CurrentShape
79//purpose :
80//=======================================================================
81
82TopoDS_Shape QADNaming::CurrentShape (const Standard_CString LabelName,
83 const Handle(TDF_Data)& DF)
84{
85 TopoDS_Shape S;
86 TDF_Label Label;
87 Standard_Boolean Found = DDF::AddLabel (DF, LabelName, Label);
88 if (!Found) {
89 cout <<"no labels"<<endl;
90 return S;
91 }
92 if (Found) {
93 Handle(TNaming_NamedShape) NS;
94 Label.FindAttribute(TNaming_NamedShape::GetID(),NS);
95 S = TNaming_Tool::CurrentShape(NS);
96 if (S.IsNull())
97 cout <<"current shape from "<< LabelName <<" is deleted"<<endl;
98 return S;
99 }
100 return S;
101}
102
103//=======================================================================
104//function : GetEntry
105//purpose :
106//=======================================================================
107
108TCollection_AsciiString QADNaming::GetEntry (const TopoDS_Shape& Shape,
109 const Handle(TDF_Data)& DF,
110 Standard_Integer& Status)
111{
112 Status = 0;
113 //Handle(TNaming_UsedShapes) US;
114 //DF->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
115
116 if (!TNaming_Tool::HasLabel (DF->Root(), Shape)) {
117 return TCollection_AsciiString ();
118 }
119 Standard_Integer Transdef;
120 TDF_Label Lab = TNaming_Tool::Label (DF->Root(), Shape,Transdef);
121 TCollection_AsciiString entry; TDF_Tool::Entry(Lab,entry);
122 //Update Status;
123 TNaming_Iterator it(Lab,DF->Transaction());
124 for (; it.More(); it.Next()) {
125 Status++;
126 if (Status == 2) break;
127 }
128 return entry;
129}
130
131//=======================================================================
132//function : GetEntry
133//purpose :
134//=======================================================================
135
136Standard_Boolean QADNaming::Entry(const Standard_Address theArguments,
137 TDF_Label& theLabel) {
138 const char** arg = (const char**)theArguments;
139 Handle(TDF_Data) DF;
140 if (!DDF::GetDF(arg[1],DF)) {
141 cout<<"Wrong df"<<endl;
142 return Standard_False;
143 }
144 DDF::AddLabel(DF,arg[2],theLabel);
145 if (!theLabel.IsNull()) return Standard_True;
146 cout<<"Wrong entry"<<endl;
147 return Standard_False;
148}
149
150//=======================================================================
151//function : IsSameShapes
152//purpose : IsSameShapes DrawShape1 DrawShape2
153//=======================================================================
154static Standard_Integer QADNaming_IsSameShapes (Draw_Interpretor& di,
155 Standard_Integer nb,
156 const char** arg) {
157 if (nb == 3) {
158 TopoDS_Shape aShape1 = DBRep::Get(arg[1]);
159 TopoDS_Shape aShape2 = DBRep::Get(arg[2]);
160 if (aShape1.IsNull() || aShape2.IsNull()) return 0;
161 if (aShape1.IsSame(aShape2)) di<<"1";
162 return 0;
163 }
164 return 1;
165}
166
167//=======================================================================
168//function : CenterOfShape
169//purpose : CenterOfShape DrawShape
170//=======================================================================
171static Standard_Integer QADNaming_CenterOfShape (Draw_Interpretor& di,
172 Standard_Integer nb,
173 const char** arg) {
174 if (nb == 2) {
175 TopoDS_Shape aShape = DBRep::Get(arg[1]);
176 if (aShape.IsNull()) return 1;
177 Standard_Real x=0,y=0,z=0;
178 float all = 0;
179 TopExp_Explorer anExp(aShape,TopAbs_VERTEX);
180 for(;anExp.More();anExp.Next(),all++) {
181 TopoDS_Vertex aVertex = TopoDS::Vertex(anExp.Current());
182 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
183 x+=aPoint.X();
184 y+=aPoint.Y();
185 z+=aPoint.Z();
186 }
187 if (all != 0) {
188 char s[100];
91322f44 189 Sprintf(s,"%f %f %f",(float)x/all,(float)y/all,(float)z/all);
7fd59977 190 di<<s;
191 return 0;
192 }
193 }
194 return 1;
195}
196
197//=======================================================================
198//function : AllCommands
199//purpose :
200//=======================================================================
201
202void QADNaming::AllCommands(Draw_Interpretor& theCommands)
203{
204 static Standard_Boolean done = Standard_False;
205 if (done) return;
206 done = Standard_True;
207
208 QADNaming::BasicCommands (theCommands);
209 QADNaming::BuilderCommands (theCommands);
210 QADNaming::IteratorsCommands (theCommands);
211 QADNaming::ToolsCommands (theCommands);
212 QADNaming::SelectionCommands (theCommands);
213
214 // auxiliary command IsSameShapes
215 theCommands.Add("IsSameShapes","IsSameShapes DrawShape1 DrawShape2",__FILE__,QADNaming_IsSameShapes, "Auxiliary methods");
216 theCommands.Add("CenterOfShape","CenterOfShape DrawShape",__FILE__,QADNaming_CenterOfShape, "Auxiliary methods");
217 // define the TCL variable Draw_NamingData
218 const char* com = "set Draw_NamingData 1";
219 theCommands.Eval(com);
220}