1 // Created on: 1997-10-20
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <QADNaming.hxx>
21 #include <TNaming_NamedShape.hxx>
22 #include <TNaming_ListOfNamedShape.hxx>
23 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
24 #include <TNaming_Tool.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_AttributeMap.hxx>
27 #include <TDF_MapIteratorOfAttributeMap.hxx>
28 #include <TDF_ChildIterator.hxx>
29 #include <TDF_Tool.hxx>
30 #include <TNaming_Name.hxx>
31 #include <TNaming.hxx>
32 #include <TNaming_Naming.hxx>
33 #include <TNaming_MapOfNamedShape.hxx>
34 #include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
35 #include <TDF_ChildIterator.hxx>
36 #include <TNaming_Selector.hxx>
37 #include <TopoDS_Shape.hxx>
39 #include <TCollection_AsciiString.hxx>
40 #include <TDF_LabelMap.hxx>
43 #include <Draw_Appli.hxx>
45 #include <Draw_Interpretor.hxx>
46 #include <Draw_Drawable3D.hxx>
48 #include <DBRep_DrawableShape.hxx>
51 //=======================================================================
54 //=======================================================================
56 static void Display (const Standard_CString Name, const TopoDS_Shape& S)
59 static Standard_Integer nbIsos = 2;
60 static Standard_Real size = 100.;
61 static Standard_Integer discret = 30;
63 Handle(DBRep_DrawableShape) D = new DBRep_DrawableShape(S,
74 //=======================================================================
75 //function : DumpNaming
77 //=======================================================================
79 static void DumpNaming (const Handle(TNaming_Naming)& naming, Draw_Interpretor& di)
81 TCollection_AsciiString Entry;
82 const TNaming_Name& AName = naming->GetName();
84 //TNaming::Print(AName.Type(),std::cout);
85 Standard_SStream aSStream1;
86 TNaming::Print(AName.Type(),aSStream1);
90 //TopAbs::Print(AName.ShapeType(),std::cout);
91 Standard_SStream aSStream2;
92 TopAbs::Print(AName.ShapeType(),aSStream2);
95 const TNaming_ListOfNamedShape& NSS = AName.Arguments();
96 for (TNaming_ListIteratorOfListOfNamedShape it(NSS); it.More(); it.Next()) {
97 TDF_Tool::Entry(it.Value()->Label(),Entry);
98 di << " " << Entry.ToCString();
100 if(!AName.StopNamedShape().IsNull()) {
101 TDF_Tool::Entry(AName.StopNamedShape()->Label(),Entry);
102 di << " Stop " << Entry.ToCString();
106 //=======================================================================
107 //function : SelectShape ou SelectGeometry
108 //purpose : "Select DF entry shape [context]",
109 //=======================================================================
111 static Standard_Integer QADNaming_Select (Draw_Interpretor& di, Standard_Integer n, const char** a)
113 if (n == 4 || n == 5) {
114 Standard_Boolean geometry = (strcmp(a[0],"SelectGeometry")==0?1:0);
116 if(!DDF::GetDF(a[1], DF)) return 1;
118 DDF::AddLabel(DF,a[2],L);
119 TNaming_Selector SL (L);
121 TopoDS_Shape S = DBRep::Get(a[3], TopAbs_SHAPE);
122 SL.Select (S, geometry);
125 TopoDS_Shape S = DBRep::Get(a[3], TopAbs_SHAPE);
126 TopoDS_Shape C = DBRep::Get(a[4], TopAbs_SHAPE);
127 SL.Select (S, C, geometry);
131 di << "QADNaming_Select : Error\n";
135 //=======================================================================
136 //function : SolveSelection
137 //purpose : "SolveSelection DF entry",
138 //=======================================================================
140 static Standard_Integer QADNaming_SolveSelection (Draw_Interpretor& di, Standard_Integer n, const char** a)
144 if (!QADNaming::Entry(a, aLabel)) return 1;
146 TNaming_Selector SL (aLabel);
151 if (!DDF::FindLabel(aLabel.Data(),a[i],aValidLab)) di<<"Warning: label "<<a[i]<<" not exists\n";
152 else valid.Add(aValidLab);
154 Standard_Boolean done = SL.Solve(valid);
155 TopoDS_Shape Res = TNaming_Tool::CurrentShape(SL.NamedShape());
156 //TopoDS_Shape Res = TNaming_Tool::CurrentShape(NS);
157 Sprintf (name,"%s_%s","new",a[2]);
161 di << "Usage: DumpSelection DF entry [validlabel1 validlabel2 ...]\n";
165 //=======================================================================
166 //function : DumpSelection
167 //purpose : DumpSelection DF entry (R)
168 //=======================================================================
170 static Standard_Integer QADNaming_DumpSelection (Draw_Interpretor& di,
171 Standard_Integer n, const char** a)
173 if (n == 3 || n == 4) {
175 if (!DDF::GetDF(a[1],DF)) return 1;
177 if (!DDF::FindLabel(DF,a[2],L)) return 1;
178 Handle(TNaming_Naming) naming;
179 if (!L.FindAttribute(TNaming_Naming::GetID(),naming)) {
180 di <<"QADNaming_DumpSelection : not a selection\n";
183 DumpNaming(naming, di);
186 Standard_Integer depth = L.Depth();
187 Standard_Integer curdepth = 0;
188 TCollection_AsciiString Entry;
189 TDF_ChildIterator it (naming->Label(),Standard_True);
190 for (;it.More();it.Next()) {
191 if (it.Value().FindAttribute(TNaming_Naming::GetID(),naming)) {
192 curdepth = (naming->Label().Depth()- depth);
193 for (Standard_Integer i = 1; i <= curdepth; i++) di << " ";
194 TDF_Tool::Entry (naming->Label(),Entry);
195 di << Entry.ToCString() << " ";
196 DumpNaming(naming, di);
203 di << "QADNaming_DumpSelection : Error\n";
207 //=======================================================================
208 //function : ArgsSelection
209 //purpose : ArgsSelection DF entry
210 //=======================================================================
212 static Standard_Integer QADNaming_ArgsSelection (Draw_Interpretor& di,
213 Standard_Integer n, const char** a)
217 if (!DDF::GetDF(a[1],DF)) return 1;
219 if (!DDF::FindLabel(DF,a[2],L)) return 1;
220 Handle(TNaming_Naming) naming;
221 if (!L.FindAttribute(TNaming_Naming::GetID(),naming)) {
222 di <<"QADNaming_DumpSelection : not a selection\n";
225 TCollection_AsciiString Entry;
226 TNaming_Selector SL (L);
227 di <<" Selection Arguments : ";
228 TDF_AttributeMap args;
230 for (TDF_MapIteratorOfAttributeMap it(args); it.More(); it.Next()) {
231 TDF_Tool::Entry(it.Key()->Label(),Entry);
232 di << Entry.ToCString() << " ";
237 di << "QADNaming_ArgsSelection : Error\n";
241 //=======================================================================
242 //function : CollectAttachment
244 //=======================================================================
246 static void CollectAttachment (const TDF_Label& root,
247 const Handle(TNaming_Naming)& naming,
248 TNaming_MapOfNamedShape& attachment)
250 TNaming_ListIteratorOfListOfNamedShape itarg;
251 const TNaming_ListOfNamedShape& args = naming->GetName().Arguments();
252 for (itarg.Initialize(args);itarg.More();itarg.Next()) {
253 if (!itarg.Value()->Label().IsDescendant(root)) attachment.Add(itarg.Value());
255 Handle(TNaming_Naming) subnaming;
256 for (TDF_ChildIterator it(naming->Label(),Standard_True);it.More();it.Next()) {
257 if (it.Value().FindAttribute(TNaming_Naming::GetID(),subnaming)) {
258 const TNaming_ListOfNamedShape& subargs = subnaming->GetName().Arguments();
259 for (itarg.Initialize(subargs);itarg.More();itarg.Next()) {
260 if (!itarg.Value()->Label().IsDescendant(root)) attachment.Add(itarg.Value());
267 //=======================================================================
268 //function : Attachment
269 //purpose : Attachment DF entry
270 //=======================================================================
272 static Standard_Integer QADNaming_Attachment (Draw_Interpretor& di,
278 if (!DDF::GetDF(a[1],DF)) return 1;
280 if (!DDF::FindLabel(DF,a[2],L)) return 1;
281 Handle(TNaming_Naming) naming;
282 TNaming_MapOfNamedShape attachment;
283 if (L.FindAttribute(TNaming_Naming::GetID(),naming)) {
284 CollectAttachment (L,naming,attachment);
287 for (TDF_ChildIterator it (L,Standard_True); it.More();it.Next()) {
288 if (it.Value().FindAttribute(TNaming_Naming::GetID(),naming)) {
289 CollectAttachment (L,naming,attachment);
294 TCollection_AsciiString Entry;
295 TDF_Tool::Entry(L,Entry);
296 di << " Attachment of " << Entry.ToCString();
298 for (TNaming_MapIteratorOfMapOfNamedShape ita (attachment); ita.More(); ita.Next()) {
299 TDF_Tool::Entry (ita.Key()->Label(),Entry);
300 di << Entry.ToCString() << " ";
305 di << "QADNaming_Attachment : Error\n";
309 //=======================================================================
310 //function : SelectionCommands
312 //=======================================================================
314 void QADNaming::SelectionCommands(Draw_Interpretor& theCommands)
317 static Standard_Boolean done = Standard_False;
319 done = Standard_True;
321 const char* g = "Naming data commands";
323 theCommands.Add("SelectShape",
324 "SelectShape DF entry shape [context]",
325 __FILE__, QADNaming_Select, g);
327 theCommands.Add("SelectGeometry",
328 "SelectGeometry DF entry shape [context]",
329 __FILE__, QADNaming_Select, g);
331 theCommands.Add("DumpSelection",
332 "DumpSelected DF entry",
333 __FILE__, QADNaming_DumpSelection, g);
335 theCommands.Add("ArgsSelection",
336 "ArgsSelection DF entry",
337 __FILE__, QADNaming_ArgsSelection, g);
339 theCommands.Add("SolveSelection",
340 "DumpSelection DF entry [validlabel1 validlabel2 ...]",
341 __FILE__, QADNaming_SolveSelection, g);
343 theCommands.Add("Attachment",
344 "Attachment DF entry",
345 __FILE__, QADNaming_Attachment, g);