7fd59977 |
1 | // File: XDEDRAW.cxx |
2 | // Created: Fri Aug 4 14:38:55 2000 |
3 | // Author: Pavel TELKOV |
4 | // <ptv@zamox.nnov.matra-dtv.fr> |
5 | |
6 | |
7 | #include <XDEDRAW.ixx> |
8 | #include <stdio.h> |
9 | |
10 | #include <TCollection_ExtendedString.hxx> |
11 | #include <TCollection_AsciiString.hxx> |
12 | #include <TColStd_HSequenceOfExtendedString.hxx> |
13 | #include <TCollection_HAsciiString.hxx> |
14 | #include <Quantity_Color.hxx> |
15 | |
16 | #include <TopoDS_Shape.hxx> |
17 | |
18 | #include <Draw.hxx> |
19 | #include <DBRep.hxx> |
20 | #include <V3d_Viewer.hxx> |
21 | #include <V3d_View.hxx> |
22 | #include <AIS_InteractiveContext.hxx> |
23 | #include <ViewerTest_Tool.hxx> |
24 | |
25 | #include <DDF_Browser.hxx> |
26 | #include <DDocStd.hxx> |
27 | #include <DDocStd_DrawDocument.hxx> |
28 | |
29 | #include <TDF_Tool.hxx> |
30 | #include <TDF_Data.hxx> |
31 | #include <TDF_LabelSequence.hxx> |
32 | #include <TDF_AttributeIterator.hxx> |
33 | #include <TDocStd_Document.hxx> |
34 | #include <TDataStd_UAttribute.hxx> |
35 | #include <TDataStd_TreeNode.hxx> |
36 | #include <TDataStd_Integer.hxx> |
37 | #include <TDataStd_Real.hxx> |
38 | #include <TDataStd_Name.hxx> |
39 | #include <TNaming_NamedShape.hxx> |
40 | #include <TDataStd_RealArray.hxx> |
41 | #include <TPrsStd_AISPresentation.hxx> |
42 | #include <TPrsStd_NamedShapeDriver.hxx> |
43 | #include <TPrsStd_AISViewer.hxx> |
44 | |
45 | #include <XCAFDoc.hxx> |
46 | #include <XCAFDoc_Color.hxx> |
47 | #include <XCAFDoc_Volume.hxx> |
48 | #include <XCAFDoc_Area.hxx> |
49 | #include <XCAFDoc_Centroid.hxx> |
50 | #include <XCAFDoc_ShapeTool.hxx> |
51 | #include <XCAFDoc_ColorTool.hxx> |
52 | #include <XCAFDoc_DocumentTool.hxx> |
53 | #include <XCAFDoc_GraphNode.hxx> |
54 | #include <XCAFDoc_LayerTool.hxx> |
55 | #include <XCAFDoc_DimTol.hxx> |
56 | #include <XCAFDoc_Material.hxx> |
57 | #include <XCAFPrs_Driver.hxx> |
58 | #include <XCAFApp_Application.hxx> |
59 | |
60 | #include <XDEDRAW_Shapes.hxx> |
61 | #include <XDEDRAW_Colors.hxx> |
62 | #include <XDEDRAW_Layers.hxx> |
63 | #include <XDEDRAW_Props.hxx> |
64 | #include <XDEDRAW_Common.hxx> |
65 | #include <XSDRAWIGES.hxx> |
66 | #include <XSDRAWSTEP.hxx> |
67 | #include <SWDRAW.hxx> |
68 | #include <XSDRAW.hxx> |
69 | #include <XCAFPrs.hxx> |
70 | #include <ViewerTest.hxx> |
71 | #include <Draw_PluginMacro.hxx> |
72 | |
73 | #include <TColStd_HArray1OfInteger.hxx> |
74 | #include <TColStd_HArray1OfReal.hxx> |
75 | |
76 | #define ZVIEW_SIZE 1000000.0 |
77 | // avoid warnings on 'extern "C"' functions returning C++ classes |
78 | #ifdef WNT |
79 | #pragma warning(4:4190) |
80 | #endif |
81 | |
82 | //======================================================================= |
83 | // Section: General commands |
84 | //======================================================================= |
85 | |
86 | //======================================================================= |
87 | //function : newDoc |
88 | //purpose : |
89 | //======================================================================= |
90 | static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
91 | { |
92 | if (argc < 2) {di<<"Give document name"<<"\n";return 1;} |
93 | |
94 | Handle(TDocStd_Document) D; |
95 | Handle(DDocStd_DrawDocument) DD; |
96 | Handle(TDocStd_Application) A; |
97 | |
98 | if (!DDocStd::Find(A)) return 1; |
99 | |
100 | if (!DDocStd::GetDocument(argv[1],D,Standard_False)) { |
101 | A->NewDocument( "MDTV-XCAF" ,D); |
102 | DD = new DDocStd_DrawDocument(D); |
103 | TDataStd_Name::Set(D->GetData()->Root(),argv[1]); |
104 | Draw::Set(argv[1],DD); |
105 | di << "document " << argv[1] << " created" << "\n"; |
106 | //DDocStd::ReturnLabel(di,D->Main()); |
107 | } |
108 | else di << argv[1] << " is already a document" << "\n"; |
109 | |
110 | return 0; |
111 | } |
112 | |
113 | |
114 | //======================================================================= |
115 | //function : saveDoc |
116 | //purpose : |
117 | //======================================================================= |
118 | static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
119 | { |
120 | Handle(TDocStd_Document) D; |
121 | Handle(TDocStd_Application) A; |
122 | if (!DDocStd::Find(A)) return 1; |
123 | |
124 | if (argc == 1) { |
125 | if (A->NbDocuments() < 1) return 1; |
126 | A->GetDocument(1, D); |
127 | } |
128 | else { |
129 | if (!DDocStd::GetDocument(argv[1],D)) return 1; |
130 | } |
131 | |
132 | if (argc == 3 ) { |
133 | TCollection_ExtendedString path (argv[2]); |
134 | A->SaveAs(D,path); |
135 | return 0; |
136 | } |
137 | if (!D->IsSaved()) { |
138 | di << "this document has never been saved" << "\n"; |
139 | return 1; |
140 | } |
141 | A->Save(D); |
142 | return 0; |
143 | } |
144 | |
145 | |
146 | //======================================================================= |
147 | //function : dump |
148 | //purpose : |
149 | //======================================================================= |
150 | static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
151 | { |
152 | if (argc<2) { |
153 | di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n"; |
154 | return 1; |
155 | } |
156 | Handle(TDocStd_Document) Doc; |
157 | DDocStd::GetDocument(argv[1], Doc); |
158 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
159 | |
160 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
161 | Standard_Boolean deep = Standard_False; |
162 | if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True; |
163 | myAssembly->Dump(deep); |
164 | return 0; |
165 | } |
166 | |
167 | |
168 | //======================================================================= |
169 | //function : StatAssembly |
170 | //purpose : recursive part of statistics |
171 | //======================================================================= |
172 | |
173 | static void StatAssembly(const TDF_Label L, |
174 | const Standard_Integer level, |
175 | Handle(TColStd_HArray1OfInteger) &HAI, |
176 | Standard_Integer &NbCentroidProp, |
177 | Standard_Integer &NbVolumeProp, |
178 | Standard_Integer &NbAreaProp, |
179 | Standard_Integer &NbShapesWithName, |
180 | Standard_Integer &NbShapesWithColor, |
181 | Standard_Integer &NbShapesWithLayer, |
182 | Handle(TDocStd_Document) &aDoc, |
183 | Standard_Boolean &PrintStructMode, |
184 | Draw_Interpretor& di) |
185 | { |
186 | if(PrintStructMode) { |
187 | for(Standard_Integer j=0; j<=level; j++) |
188 | di<<" "; |
189 | } |
190 | TCollection_AsciiString Entry; |
191 | TDF_Tool::Entry(L, Entry); |
192 | if(PrintStructMode) di<<Entry.ToCString(); |
193 | |
194 | Handle(TDataStd_Name) Name; |
195 | if(L.FindAttribute(TDataStd_Name::GetID(), Name)) { |
196 | NbShapesWithName++; |
197 | if(PrintStructMode) { |
198 | TCollection_AsciiString AsciiStringName(Name->Get(),'?'); |
199 | di<<" "<<AsciiStringName.ToCString()<<" has attributes: "; |
200 | } |
201 | } |
202 | else { |
203 | if(PrintStructMode) di<<" NoName has attributes: "; |
204 | } |
205 | |
206 | Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid); |
207 | if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) { |
208 | if(PrintStructMode) di<<"Centroid "; |
209 | NbCentroidProp++; |
210 | } |
211 | Standard_Real tmp; |
212 | if(XCAFDoc_Volume::Get(L,tmp)) { |
213 | if(PrintStructMode) di<<"Volume("<<tmp<<") "; |
214 | NbVolumeProp++; |
215 | } |
216 | if(XCAFDoc_Area::Get(L,tmp)) { |
217 | if(PrintStructMode) di<<"Area("<<tmp<<") "; |
218 | NbAreaProp++; |
219 | } |
220 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main()); |
221 | Quantity_Color col; |
222 | Standard_Boolean IsColor = Standard_False; |
223 | if(CTool->GetColor(L,XCAFDoc_ColorGen,col)) |
224 | IsColor = Standard_True; |
225 | else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col)) |
226 | IsColor = Standard_True; |
227 | else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col)) |
228 | IsColor = Standard_True; |
229 | if(IsColor) { |
230 | TCollection_AsciiString Entry1; |
231 | Entry1 = col.StringName(col.Name()); |
232 | if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") "; |
233 | NbShapesWithColor++; |
234 | } |
235 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main()); |
236 | Handle(TColStd_HSequenceOfExtendedString) aLayerS; |
237 | LTool->GetLayers(L, aLayerS); |
238 | if(!aLayerS.IsNull() && aLayerS->Length()>0) { |
239 | if(PrintStructMode) { |
240 | di<<"Layer("; |
241 | for(Standard_Integer i=1; i<=aLayerS->Length(); i++) { |
242 | TCollection_AsciiString Entry2(aLayerS->Value(i),'?'); |
243 | if(i==1) |
244 | di<<"\""<<Entry2.ToCString()<<"\""; |
245 | else |
246 | di<<" "<<"\""<<Entry2.ToCString()<<"\""; |
247 | } |
248 | di<<") "; |
249 | } |
250 | NbShapesWithLayer++; |
251 | } |
252 | if(PrintStructMode) di<<"\n"; |
253 | |
254 | HAI->SetValue(level, HAI->Value(level)+1 ); |
255 | if(L.HasChild()) { |
256 | for(Standard_Integer i=1; i<=L.NbChildren(); i++) { |
257 | StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp, |
258 | NbAreaProp, NbShapesWithName, NbShapesWithColor, |
259 | NbShapesWithLayer, aDoc, PrintStructMode, di); |
260 | } |
261 | } |
262 | |
263 | } |
264 | |
265 | |
266 | //======================================================================= |
267 | //function : statdoc |
268 | //purpose : |
269 | //======================================================================= |
270 | static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
271 | { |
272 | if (argc<2) { |
273 | di<<"Use: "<<argv[0]<<" Doc "<<"\n"; |
274 | return 1; |
275 | } |
276 | Handle(TDocStd_Document) Doc; |
277 | DDocStd::GetDocument(argv[1], Doc); |
278 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
279 | |
280 | Standard_Boolean PrintStructMode = (argc==3); |
281 | Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
282 | |
283 | TDF_LabelSequence SeqLabels; |
284 | aTool->GetShapes(SeqLabels); |
285 | if(SeqLabels.Length()<=0) return 0; |
286 | if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n"; |
287 | Standard_Integer level=0; |
288 | Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0; |
289 | Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0; |
290 | Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20); |
291 | Standard_Integer i=0; |
292 | for(i=0; i<=20; i++) HAI->SetValue(i,0); |
293 | for(i=1; i<=SeqLabels.Length(); i++) { |
294 | StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp, |
295 | NbAreaProp, NbShapesWithName, NbShapesWithColor, |
296 | NbShapesWithLayer, Doc, PrintStructMode, di); |
297 | } |
298 | Standard_Integer NbLabelsShape = 0; |
299 | di<<"\n"<<"Statistis of shapes in the document:"<<"\n"; |
300 | for(i=0; i<=20; i++) { |
301 | if(HAI->Value(i)==0) break; |
302 | //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n"; |
303 | di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n"; |
304 | NbLabelsShape = NbLabelsShape + HAI->Value(i); |
305 | } |
306 | di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n"; |
307 | di<<"Number of labels with name = "<<NbShapesWithName<<"\n"; |
308 | di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n"; |
309 | di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n"; |
310 | |
311 | di<<"\n"<<"Statistis of Props in the document:"<<"\n"; |
312 | di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n"; |
313 | di<<"Number of Volume Props = "<<NbVolumeProp<<"\n"; |
314 | di<<"Number of Area Props = "<<NbAreaProp<<"\n"; |
315 | |
316 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); |
317 | TDF_LabelSequence CLabels; |
318 | CTool->GetColors(CLabels); |
319 | di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n"; |
320 | if(CLabels.Length()>0) { |
321 | for(i=1; i<=CLabels.Length(); i++) { |
322 | TDF_Label aLabel = CLabels.Value(i); |
323 | Quantity_Color col; |
324 | CTool->GetColor(aLabel, col); |
325 | di<<col.StringName(col.Name())<<" "; |
326 | } |
327 | di<<"\n"; |
328 | } |
329 | |
330 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
331 | TDF_LabelSequence LLabels; |
332 | LTool->GetLayerLabels(LLabels); |
333 | di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n"; |
334 | if(LLabels.Length()>0) { |
335 | for(i=1; i<=LLabels.Length(); i++) { |
336 | TDF_Label aLabel = LLabels.Value(i); |
337 | TCollection_ExtendedString layerName; |
338 | LTool->GetLayer(aLabel, layerName); |
339 | TCollection_AsciiString Entry(layerName,'?'); |
340 | di<<"\""<<Entry.ToCString() <<"\" "; |
341 | } |
342 | di<<"\n"; |
343 | } |
344 | |
345 | di<<"\n"; |
346 | return 0; |
347 | } |
348 | |
349 | |
350 | //======================================================================= |
351 | //function : setPrs |
352 | //purpose : |
353 | //======================================================================= |
354 | static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
355 | { |
356 | if (argc <2) { |
357 | di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n"; |
358 | return 1; |
359 | } |
360 | |
361 | Handle(TDocStd_Document) Doc; |
362 | DDocStd::GetDocument(argv[1], Doc); |
363 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
364 | |
365 | // collect sequence of labels to set presentation |
366 | Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
367 | TDF_LabelSequence seq; |
368 | if ( argc >2 ) { |
369 | for ( Standard_Integer i=2; i < argc; i++ ) { |
370 | TDF_Label aLabel; |
371 | TDF_Tool::Label(Doc->GetData(), argv[i], aLabel); |
372 | if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) { |
373 | di << argv[i] << " is not a valid shape label!"; |
374 | continue; |
375 | } |
376 | seq.Append ( aLabel ); |
377 | } |
378 | } |
379 | else { |
380 | shapes->GetShapes ( seq ); |
381 | } |
382 | |
383 | // set presentations |
384 | Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); |
385 | for ( Standard_Integer i=1; i <= seq.Length(); i++ ) { |
386 | Handle(TPrsStd_AISPresentation) prs; |
387 | if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) { |
388 | prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID()); |
389 | prs->SetMaterial ( Graphic3d_NOM_PLASTIC ); |
390 | } |
391 | // Quantity_Color Col; |
392 | // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) ) |
393 | // prs->SetColor ( Col.Name() ); |
394 | // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) ) |
395 | // prs->SetColor ( Col.Name() ); |
396 | } |
397 | return 0; |
398 | } |
399 | |
400 | |
401 | //======================================================================= |
402 | //function : show |
403 | //purpose : |
404 | //======================================================================= |
405 | static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
406 | { |
407 | if (argc <2) { |
408 | di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n"; |
409 | return 1; |
410 | } |
411 | |
412 | Handle(TDocStd_Document) Doc; |
413 | DDocStd::GetDocument(argv[1], Doc); |
414 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
415 | |
416 | // init viewer |
417 | // char string[260]; |
418 | // sprintf ( string, "AISInitViewer %s", argv[1] ); |
419 | // di.Eval ( string ); |
420 | TDF_Label acces = Doc->GetData()->Root(); |
421 | Handle(TPrsStd_AISViewer) viewer; |
422 | if (!TPrsStd_AISViewer::Find (acces,viewer)) { |
423 | TCollection_AsciiString title; |
424 | title.Prepend(argv[1]); |
425 | title.Prepend("_"); |
426 | title.Prepend("Document"); |
427 | Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString()); |
428 | viewer = TPrsStd_AISViewer::New (acces,vw); |
429 | } |
430 | ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext()); |
431 | |
432 | //szv:CAX-TRJ7 c2-pe-214.stp was clipped |
433 | viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE); |
434 | //DDF::ReturnLabel(di,viewer->Label()); |
435 | |
436 | // collect sequence of labels to display |
437 | Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
438 | TDF_LabelSequence seq; |
439 | if ( argc >2 ) { |
440 | for ( Standard_Integer i=2; i < argc; i++ ) { |
441 | TDF_Label aLabel; |
442 | TDF_Tool::Label(Doc->GetData(), argv[i], aLabel); |
443 | if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) { |
444 | di << argv[i] << " is not a valid shape label!"; |
445 | continue; |
446 | } |
447 | seq.Append ( aLabel ); |
448 | } |
449 | } |
450 | else { |
451 | shapes->GetFreeShapes ( seq ); |
452 | } |
453 | |
454 | // set presentations and show |
455 | //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); |
456 | for ( Standard_Integer i=1; i <= seq.Length(); i++ ) { |
457 | Handle(TPrsStd_AISPresentation) prs; |
458 | if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) { |
459 | prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID()); |
460 | prs->SetMaterial ( Graphic3d_NOM_PLASTIC ); |
461 | } |
462 | // Quantity_Color Col; |
463 | // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) ) |
464 | // prs->SetColor ( Col.Name() ); |
465 | // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) ) |
466 | // prs->SetColor ( Col.Name() ); |
467 | prs->Display(Standard_True); |
468 | } |
469 | TPrsStd_AISViewer::Update(Doc->GetData()->Root()); |
470 | return 0; |
471 | } |
472 | |
473 | |
474 | //======================================================================= |
475 | //function : xwd |
476 | //purpose : |
477 | //======================================================================= |
478 | static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
479 | { |
480 | if (argc <3) { |
481 | di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n"; |
482 | return 1; |
483 | } |
484 | |
485 | Handle(TDocStd_Document) Doc; |
486 | DDocStd::GetDocument(argv[1], Doc); |
487 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
488 | |
489 | Handle(AIS_InteractiveContext) IC; |
490 | if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) { |
491 | di << "Cannot find viewer for document " << argv[1] << "\n"; |
492 | return 1; |
493 | } |
494 | |
495 | Handle(V3d_Viewer) viewer = IC->CurrentViewer(); |
496 | viewer->InitActiveViews(); |
497 | if ( viewer->MoreActiveViews() ) { |
498 | viewer->ActiveView()->Dump ( argv[2] ); |
499 | } |
500 | else { |
501 | di << "Cannot find an active view in a viewer " << argv[1] << "\n"; |
502 | return 1; |
503 | } |
504 | |
505 | return 0; |
506 | } |
507 | |
508 | |
509 | //======================================================================= |
510 | //function : XAttributeValue |
511 | //purpose : |
512 | //======================================================================= |
513 | static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
514 | { |
515 | if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; } |
516 | Handle(DDF_Browser) browser = |
517 | Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True)); |
518 | if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; } |
519 | |
520 | TDF_Label lab; |
521 | TDF_Tool::Label(browser->Data(),argv[2],lab); |
522 | if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; } |
523 | |
524 | Standard_Integer num = atoi ( argv[3] ); |
525 | TDF_AttributeIterator itr(lab,Standard_False); |
526 | for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); |
527 | |
528 | if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; } |
529 | |
530 | const Handle(TDF_Attribute)& att = itr.Value(); |
531 | if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) { |
532 | Standard_CString type; |
533 | if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link"; |
534 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link"; |
535 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link"; |
536 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link"; |
537 | else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link"; |
538 | else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link"; |
539 | else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link"; |
540 | else return 0; |
541 | Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att); |
542 | TCollection_AsciiString ref; |
543 | if ( TN->HasFather() ) { |
544 | TDF_Tool::Entry ( TN->Father()->Label(), ref ); |
545 | di << type << " ==> " << ref.ToCString(); |
546 | } |
547 | else { |
548 | di << type << " <== (" << ref.ToCString(); |
549 | Handle(TDataStd_TreeNode) child = TN->First(); |
550 | while ( ! child.IsNull() ) { |
551 | TDF_Tool::Entry ( child->Label(), ref ); |
552 | if ( child != TN->First() ) di << ", "; |
553 | di << ref.ToCString(); |
554 | child = child->Next(); |
555 | } |
556 | di << ")"; |
557 | } |
558 | } |
559 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) { |
560 | Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att ); |
561 | TCollection_AsciiString str ( val->Get() ); |
562 | di << str.ToCString(); |
563 | } |
564 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) { |
565 | Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att ); |
566 | TCollection_AsciiString str ( val->Get() ); |
567 | di << str.ToCString(); |
568 | } |
569 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) { |
570 | Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att ); |
571 | TCollection_AsciiString str ( val->Get() ); |
572 | di << str.ToCString(); |
573 | } |
574 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) { |
575 | Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att ); |
576 | TCollection_AsciiString str ( val->Get() ); |
577 | di << str.ToCString(); |
578 | } |
579 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) { |
580 | Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att ); |
581 | gp_Pnt myCentroid = val->Get(); |
582 | di << "(" ; |
583 | di << myCentroid.X(); |
584 | di <<" , "; |
585 | di << myCentroid.Y(); |
586 | di <<" , "; |
587 | di << myCentroid.Z(); |
588 | di << ")"; |
589 | } |
590 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) { |
591 | Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att ); |
592 | TCollection_AsciiString str ( val->Get(), '?' ); |
593 | di << str.ToCString(); |
594 | } |
595 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) { |
596 | Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att ); |
597 | for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) { |
598 | if ( j > val->Lower() ) di << ", "; |
599 | TCollection_AsciiString str ( val->Value(j) ); |
600 | di << str.ToCString(); |
601 | } |
602 | } |
603 | else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) { |
604 | Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att ); |
605 | TopoDS_Shape S = val->Get(); |
606 | di << S.TShape()->DynamicType()->Name(); |
607 | if ( ! S.Location().IsIdentity() ) di << "(located)"; |
608 | } |
609 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) { |
610 | if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly"; |
611 | if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible"; |
612 | } |
613 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) { |
614 | Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att ); |
615 | Quantity_Color C = val->GetColor(); |
616 | char string[260]; |
617 | sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ), |
618 | C.Red(), C.Green(), C.Blue() ); |
619 | di << string; |
620 | } |
621 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) { |
622 | Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att ); |
623 | Standard_Integer kind = val->GetKind(); |
624 | Handle(TColStd_HArray1OfReal) HAR = val->GetVal(); |
625 | if(kind<20) { //dimension |
626 | di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])"; |
627 | } |
628 | else { |
629 | switch(kind) { |
630 | case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break; |
631 | case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break; |
632 | case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break; |
633 | case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break; |
634 | case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break; |
635 | case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break; |
636 | case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break; |
637 | case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break; |
638 | case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break; |
639 | case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break; |
640 | case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break; |
641 | case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break; |
642 | case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break; |
643 | case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break; |
644 | case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break; |
645 | case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break; |
646 | case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break; |
647 | case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break; |
648 | case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break; |
649 | case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break; |
650 | case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break; |
651 | } |
652 | } |
653 | } |
654 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) { |
655 | Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att ); |
656 | Standard_Real dens = val->GetDensity(); |
657 | Standard_CString dimdens = "g/cu sm"; |
658 | if(dens==0) |
659 | di<<val->GetName()->ToCString(); |
660 | else |
661 | di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")"; |
662 | } |
663 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) { |
664 | Standard_CString type; |
665 | if ( att->ID() == XCAFDoc::LayerRefGUID() ) { |
666 | type = "Layer Instance Link"; |
667 | } |
668 | else if ( att->ID() == XCAFDoc::SHUORefGUID() ) { |
669 | type = "SHUO Instance Link"; |
670 | } |
671 | else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) { |
672 | type = "DatumToler Link"; |
673 | } |
674 | else return 0; |
675 | |
676 | Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att); |
677 | TCollection_AsciiString ref; |
678 | Standard_Integer ii = 1; |
679 | if (DETGN->NbFathers()!=0) { |
680 | |
681 | TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref ); |
682 | di << type<< " ==> (" << ref.ToCString(); |
683 | for (ii = 2; ii <= DETGN->NbFathers(); ii++) { |
684 | TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref ); |
685 | di << ", " << ref.ToCString(); |
686 | } |
687 | di << ") "; |
688 | } |
689 | ii = 1; |
690 | if (DETGN->NbChildren()!=0) { |
691 | TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref ); |
692 | di << type<< " <== (" << ref.ToCString(); |
693 | for (ii = 2; ii <= DETGN->NbChildren(); ii++) { |
694 | TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref ); |
695 | di << ", " << ref.ToCString(); |
696 | } |
697 | di << ")"; |
698 | } |
699 | } |
700 | return 0; |
701 | } |
702 | |
703 | |
704 | //======================================================================= |
705 | //function : setviewName |
706 | //purpose : |
707 | //======================================================================= |
708 | static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
709 | { |
710 | if (argc <2) { |
711 | di<<"Use: "<<argv[0]<<" (1/0)"<<"\n"; |
712 | return 1; |
713 | } |
714 | Standard_Boolean mode = Standard_False; |
715 | if (atoi(argv[1]) == 1) mode = Standard_True; |
716 | XCAFPrs::SetViewNameMode(mode); |
717 | return 0; |
718 | } |
719 | |
720 | |
721 | //======================================================================= |
722 | //function : getviewName |
723 | //purpose : auxilary |
724 | //======================================================================= |
725 | |
726 | static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) |
727 | { |
728 | if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n"; |
729 | else di << "Display names OFF"<< "\n"; |
730 | return 0; |
731 | } |
732 | |
733 | |
734 | //======================================================================= |
735 | //function : Init |
736 | //purpose : |
737 | //======================================================================= |
738 | |
739 | void XDEDRAW::Init(Draw_Interpretor& di) |
740 | { |
741 | |
742 | static Standard_Boolean initactor = Standard_False; |
743 | if (initactor) return; initactor = Standard_True; |
744 | |
745 | // OCAF *** szy: use <pload> command |
746 | |
747 | // DDF::AllCommands(di); |
748 | // DNaming::AllCommands(di); |
749 | // DDataStd::AllCommands(di); |
750 | // DPrsStd::AllCommands(di); |
751 | //DFunction::AllCommands(di); |
752 | // DDocStd::AllCommands(di); |
753 | |
754 | // ViewerTest::Commands (di); *** szy: use <pload> command |
755 | |
756 | // init XCAF application (if not yet done) |
757 | XCAFApp_Application::GetApplication(); |
758 | |
759 | //===================================== |
760 | // General commands |
761 | //===================================== |
762 | |
763 | Standard_CString g = "XDE general commands"; |
764 | |
765 | di.Add ("XNewDoc","DocName \t: Create new DECAF document", |
766 | __FILE__, newDoc, g); |
767 | |
768 | di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session", |
769 | __FILE__, saveDoc, g); |
770 | |
771 | di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure", |
772 | __FILE__, dump, g); |
773 | |
774 | di.Add ("XStat","Doc \t: Print statistics of document", |
775 | __FILE__, statdoc, g); |
776 | |
777 | di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc", |
778 | __FILE__, setPrs, g); |
779 | |
780 | di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window", |
781 | __FILE__, show, g); |
782 | |
783 | di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file", |
784 | __FILE__, xwd, g); |
785 | |
786 | di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser", |
787 | __FILE__, XAttributeValue, g); |
788 | |
789 | di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.", |
790 | __FILE__, setviewName, g); |
791 | |
792 | di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.", |
793 | __FILE__, getviewName, g); |
794 | |
795 | // Specialized commands |
796 | XDEDRAW_Shapes::InitCommands ( di ); |
797 | XDEDRAW_Colors::InitCommands ( di ); |
798 | XDEDRAW_Layers::InitCommands ( di ); |
799 | XDEDRAW_Props::InitCommands ( di ); |
800 | XDEDRAW_Common::InitCommands ( di );//moved from EXE |
801 | |
802 | } |
803 | |
804 | |
805 | //============================================================================== |
806 | // XDEDRAW::Factory |
807 | //============================================================================== |
808 | void XDEDRAW::Factory(Draw_Interpretor& theDI) |
809 | { |
810 | XSDRAWIGES::InitSelect(); |
811 | XSDRAWIGES::InitToBRep(theDI); |
812 | XSDRAWIGES::InitFromBRep(theDI); |
813 | |
814 | XSDRAWSTEP::InitCommands(theDI); |
815 | |
816 | SWDRAW::Init(theDI); |
817 | XSDRAW::LoadDraw(theDI); |
818 | |
819 | XDEDRAW::Init(theDI); |
820 | |
821 | #ifdef DEB |
822 | theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n"; |
823 | #endif |
824 | } |
825 | |
826 | // Declare entry point PLUGINFACTORY |
827 | DPLUGIN(XDEDRAW) |